corbacontext.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00010 /*
00011   AUTHOR(S): Darryl Kang (dk)
00012 
00013   RCS information
00014    $Name: OSB_060808 $
00015    $Revision: 1.24 $
00016 
00017   License
00018    OSB rating and billing library for communication networks
00019    Copyright (C) 2004, 2005, 2006  OSB systems
00020 
00021    This file may be distributed and/or modify under the terms of the
00022    GNU General Public License (GPL) as published by the Free Software
00023    Foundation which is provided in the file LICENSE.GPL included in the
00024    packaging of this file.
00025 
00026    The file is distributed in the hope that it will be useful, but WITHOUT
00027    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00028    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00029    for more details.
00030 
00031    Holders of a OSB Commercial License may use this file under the terms
00032    and conditions of this commercial license.
00033  */
00034 #ifndef _CORBACONTEXT_H_
00035 #define _CORBACONTEXT_H_
00036 
00037 // *********************************************************************
00038 // included header files
00039 // + standard includes
00040 #include <string>
00041 
00042 // + libraries
00043 #include <ace/Reactor.h>
00044 
00045 #include <chrono.h>
00046 #include <configuration.h>
00047 #include <dbsession.h>
00048 #include <filelocklog.h>
00049 #include <osbmsgcat.h>
00050 
00051 // + class declarations
00052 namespace OSB_DB {
00053     class Session;
00054 }
00055 
00056 #define VERSION_STR "OSB Administration Server 4.01"
00057 #define COMPILED_STR "\n(" SYSTEM ", " ORACLE_VERSION ")\n" \
00058                      "Compiled " __DATE__ " on " HOSTNAME "\n"
00059 
00060 
00061 // *********************************************************************
00062 // namespace extensions
00063 namespace OSB_CORBA {
00064 
00075     class CorbaContext
00076     {
00077     public:
00079         CorbaContext()
00080           : sessionCtrl_(true),
00081             msgCatInit_(true),
00082             logger_(4)
00083         {
00084             OSB_LIB::Log::setInstance(&logger_);
00085         }
00086 
00088 
00089 
00090         OSB_DB::SessionCtrl sessionCtrl_;
00092         OSB_LIB::MsgCat::Init msgCatInit_;
00094 
00103         void initialise(OSB_DB::Session& session);
00104 
00106 
00107 
00108         OSB_APP::FileLockLog logger_;
00110         bool openLog(
00111             const std::string& app,
00112             const std::string& dir
00113         );
00121         std::string logPath() const;
00123         void closeLog();
00125 
00133         struct Config {
00135             Config() : hostExist(false),
00136                        hostName("localhost"),
00137                        portNo("0"),
00138                        logDir(".") {}
00139 
00141             bool hostExist;
00142 
00144             std::string hostName;
00145             std::string portNo;
00146 
00148             std::string logDir;
00149         };
00150 
00152         Config config;
00153 
00155         const Config configDefaults;
00156 
00163         struct Option {
00165             Option()
00166                 : debugLevel(2), verbose(false) {}
00168             int debugLevel;
00170             bool verbose;
00171         };
00172 
00174         Option option;
00175 
00177         std::string appName_;
00179         OSB_LIB::ModuleId module_;
00180 
00182         void checkNlsLang();
00183 
00185         int handleArgs(int argc, char** argv);
00186 
00192         void printHeader(const std::string& tag);
00193 
00195         void printTrailer();
00196 
00198         void printUsage();
00199 
00201         void printNamingServiceInfo();
00202     private:
00212         long readConfig(OSB_DB::Session& session, std::ostream& strm);
00213     };                                   // CorbaContext
00214 
00215     // ********************************************************************
00216     // Define the eventHandle to overload the handle_singal function
00217     class SignalHandler : public ACE_Event_Handler {
00218     public:
00219         SignalHandler(CorbaContext::Option& option);
00220 
00221     private:
00222         int handle_signal(int signum, siginfo_t*, ucontext_t*);
00223 
00224     private:
00225         CorbaContext::Option& option_;
00226     };
00227 }
00228 // ********************************************************************
00229 // local declaration
00230 namespace {
00231 
00232     template <typename T1, typename T2>
00233     void handleRcSwitch(
00234               OSB_LIB::ModuleConfig::RetConvert rc,
00235               T1*                               cfg,
00236               T1                                min,
00237         const T2&                               dft,
00238               std::ostream&                     strm
00239     )
00240     {
00241         switch (rc) {
00242         case OSB_LIB::ModuleConfig::rcNotFound:
00243             strm << "Warning: Not configured, using default of "
00244                  << dft;
00245             break;
00246 
00247         case OSB_LIB::ModuleConfig::rcTypeMismatch:
00248             strm << "Warning: Type mismatch, using default of "
00249                  << dft;
00250             break;
00251 
00252         case OSB_LIB::ModuleConfig::rcErrConvert:
00253             strm << "Warning: Error on convert, using default of "
00254                  << dft;
00255             break;
00256 
00257         case OSB_LIB::ModuleConfig::rcSuccess:
00258             if (*cfg < min) {
00259                 *cfg = dft;
00260                 strm << "Warning: Value must be at least "
00261                      << min << ", using default of "
00262                      << dft;
00263             }
00264             else {
00265                 strm << *cfg;
00266             }
00267             break;
00268         }
00269     }                                   // end of handleRcSwitch
00270 }                                       // local namespace
00271 #endif                                  // #ifndef _CORBACONTEXT_H_

Generated on Sat Sep 2 14:25:51 2006 for OSB Library by  doxygen 1.4.7