00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef _TWEEK_SUBJECT_MANAGER_IMPL_H_
00038 #define _TWEEK_SUBJECT_MANAGER_IMPL_H_
00039
00040 #include <tweek/tweekConfig.h>
00041
00042 #include <string>
00043 #include <map>
00044 #include <vpr/vpr.h>
00045 #include <vpr/Sync/Mutex.h>
00046 #include <vpr/Sync/Guard.h>
00047 #include <vpr/Util/GUID.h>
00048
00049 #include <tweek/CORBA/Subject.h>
00050 #include <tweek/CORBA/SubjectManager.h>
00051
00052
00053 namespace tweek
00054 {
00055
00056 class CorbaManager;
00057 class SubjectImpl;
00058
00067 class TWEEK_CLASS_API SubjectManagerImpl
00068 : public POA_tweek::SubjectManager,
00069 public PortableServer::RefCountServantBase
00070 {
00071 public:
00072 virtual ~SubjectManagerImpl();
00073
00091 void registerSubject(SubjectImpl* subject, const char* name);
00092
00104 vpr::ReturnStatus unregisterSubject(const char* name);
00105
00110 virtual Subject_ptr getSubject(const char* name);
00111
00116 virtual tweek::SubjectManager::SubjectList* getAllSubjects();
00117
00122 virtual tweek::SubjectManager::SubjectManagerInfoList* getInfo();
00123
00132 virtual char* getName();
00133
00134 void setName(const std::string& name)
00135 {
00136 mName = name;
00137 }
00138
00148 void setApplicationName(const std::string& appName)
00149 {
00150 addInfoItem(std::string(APPNAME_KEY), appName);
00151 }
00152
00162 void setUserName(const std::string& userName)
00163 {
00164 addInfoItem(USERNAME_KEY, userName);
00165 }
00166
00171 void addInfoItem(const std::string& key, const std::string& value)
00172 {
00173 vpr::Guard<vpr::Mutex> lock(mInfoMapMutex);
00174 mInfoMap[key] = value;
00175 }
00176
00177 const vpr::GUID& getGUID() const
00178 {
00179 return mGUID;
00180 }
00181
00182 protected:
00183
00184 friend class tweek::CorbaManager;
00185
00190 SubjectManagerImpl(const CorbaManager& corba_mgr)
00191 : mCorbaMgr(corba_mgr), mGUID(), mName("")
00192 {
00193 mGUID.generate();
00194 initInfoMap();
00195 }
00196
00197
00198
00199
00200 SubjectManagerImpl(const SubjectManagerImpl& sm);
00201
00202 void operator=(const SubjectManagerImpl& sm)
00203 {
00204 ;
00205 }
00206
00207 void registerSubject(Subject_ptr subject, const std::string& name);
00208
00213 void initInfoMap();
00214
00215 private:
00216 const CorbaManager& mCorbaMgr;
00217 vpr::GUID mGUID;
00218 std::string mName;
00219
00220 typedef std::map<std::string, Subject_ptr> subject_map_t;
00221 subject_map_t mSubjects;
00222 vpr::Mutex mSubjectsMutex;
00223
00224 typedef std::map<std::string, PortableServer::ObjectId_var> subject_id_map_t;
00225 subject_id_map_t mSubjectIds;
00226 vpr::Mutex mSubjectIdsMutex;
00227
00228 std::map<std::string, std::string> mInfoMap;
00229 vpr::Mutex mInfoMapMutex;
00230
00231 static const std::string USERNAME_KEY;
00232 static const std::string APPNAME_KEY;
00233 };
00234
00235 }
00236
00237 #endif