util/Global.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      Global.h
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   The global object (a stack for all pseudo static stuff).
00006 Version:   $Id: Global.h 14440 2005-12-26 13:13:00Z ruff $
00007 ------------------------------------------------------------------------------*/
00008 
00009 #ifndef ORG_XMLBLASTER_UTIL_GLOBAL_H
00010 #define ORG_XMLBLASTER_UTIL_GLOBAL_H
00011 
00012 #include <util/xmlBlasterDef.h>
00013 #include <util/I_Log.h>
00014 #include <util/LogManager.h>
00015 #include <util/XmlBlasterException.h>
00016 #include <util/Property.h>
00017 #include <util/SessionName.h>
00018 #include <util/ReferenceCounterBase.h>
00019 #include <util/ReferenceHolder.h>
00020 
00021 #include <client/protocol/CbServerPluginManager.h>
00022 #include <util/dispatch/DispatchManager.h>
00023 #include <util/Timeout.h>
00024 
00025 #include <string>
00026 #include <map>
00027 
00028 // for managed objects
00029 #include <util/objman.h>
00030 
00031 namespace org { namespace xmlBlaster { namespace util {
00032 
00039 Dll_Export std::string waitOnKeyboardHit(const std::string &str);
00040 
00051 typedef struct ArgsStruct {
00052    size_t argc;
00053    char **argv;
00054 } ArgsStruct_T;
00055 
00056 class org::xmlBlaster::util::Global;
00057 typedef org::xmlBlaster::util::ReferenceHolder<org::xmlBlaster::util::Global> GlobalRef;
00058 
00062 class Dll_Export Global : public ReferenceCounterBase {
00063 
00064 friend Global& getInstance(const std::string &instanceName);
00065 
00066 // required for managed objects
00067 template <class TYPE> friend class ManagedObject;
00068 friend class Object_Lifetime_Manager;
00069 
00070 typedef std::map<std::string, GlobalRef> GlobalRefMap;
00071 typedef std::map<std::string, Global*> GlobalMap;
00072 
00073 private:
00074    const std::string      ME;
00075    Property*              property_;
00076    int                    args_;
00077    const char * const*    argv_;
00078    bool                   isInitialized_;
00079    org::xmlBlaster::util::LogManager logManager_;
00080    org::xmlBlaster::client::protocol::CbServerPluginManager* cbServerPluginManager_;
00081    org::xmlBlaster::util::dispatch::DispatchManager* dispatchManager_;
00082    Timeout*               pingTimer_;
00083    std::string            id_;
00084    std::string            immutableId_;
00085    std::string            instanceName_; 
00086    mutable std::string    instanceId_;   
00087    thread::Mutex          pingerMutex_;  
00088    static thread::Mutex   globalMutex_;  
00089    org::xmlBlaster::util::SessionNameRef sessionName_;  
00090    static GlobalRefMap    globalRefMap_; 
00091    static GlobalMap       globalMap_;    
00092    static Global*         global_;       
00094    void copy();
00095 
00096 public:
00101    Global();
00102    // Global(const Global &global);
00103    Global& operator =(const Global &);
00104    ~Global();
00105 
00109    int getArgs();
00110 
00116    const char * const* getArgc();
00117 
00137    void fillArgs(ArgsStruct_T &args);
00138 
00143    void freeArgs(ArgsStruct_T &args);
00144 
00151    static Global& getInstance(std::string name="default");
00152 
00166    GlobalRef createInstance(const std::string& name, const Property::MapType *propertyMapP=NULL, bool holdReferenceCount=false);
00167 
00173    bool containsInstance(const std::string& name);
00174 
00182    bool destroyInstance(const std::string &instanceName);
00183 
00188    const std::string& getInstanceName();
00189 
00194    bool wantsHelp();
00195 
00201    static std::string& getVersion();
00202 
00208    static std::string& getRevisionNumber();
00209 
00214    static std::string& getReleaseId();
00215 
00221    static std::string& getBuildTimestamp();
00222 
00227    static std::string& getCompiler();
00228 
00233    static std::string& getDefaultProtocol();
00234  
00238    static std::string usage();
00239 
00244    Global& initialize(int args=0, const char * const argv[]=0);
00245 
00251    Global& initialize(const org::xmlBlaster::util::Property::MapType &propertyMap);
00252 
00256    org::xmlBlaster::util::LogManager& getLogManager();
00257 
00270    org::xmlBlaster::util::I_Log& getLog(const std::string &logName="org.xmlBlaster");
00271 
00275    Property& getProperty() const;
00276 
00277    std::string getLocalIP() const;
00278 
00282    std::string getBootstrapHostname() const;
00283 
00284    std::string getCbHostname() const;
00285 
00286    org::xmlBlaster::client::protocol::CbServerPluginManager& getCbServerPluginManager();
00287 
00288    org::xmlBlaster::util::dispatch::DispatchManager& getDispatchManager();
00289 
00290    Timeout& getPingTimer();
00291 
00296    static const std::string& getBoolAsString(bool val);
00297 
00301    void setSessionName(org::xmlBlaster::util::SessionNameRef sessionName);
00302 
00306    org::xmlBlaster::util::SessionNameRef getSessionName() const;
00307 
00314    std::string getId() const;
00315 
00321    std::string getStrippedId() const;
00322 
00330    std::string getImmutableId() const;
00331 
00337    std::string getStrippedImmutableId() const;
00338 
00345    std::string getStrippedString(const std::string& text) const;
00346 
00353    void setId(const std::string& id);
00354    
00359    void setImmutableId(const std::string& id);
00360 
00364    void resetInstanceId();
00365 
00371    std::string getInstanceId() const;
00372 };
00373 
00374 }}} // namespace
00375 
00376 # endif // ORG_XMLBLASTER_UTIL_GLOBAL_H