19 #ifndef INCLUDE_RCF_OBJECTFACTORYSERVICE_HPP
20 #define INCLUDE_RCF_OBJECTFACTORYSERVICE_HPP
26 #include <boost/cstdint.hpp>
27 #include <boost/noncopyable.hpp>
28 #include <boost/shared_ptr.hpp>
30 #include <RCF/Export.hpp>
31 #include <RCF/GetInterfaceName.hpp>
32 #include <RCF/RcfServer.hpp>
33 #include <RCF/Service.hpp>
34 #include <RCF/StubFactory.hpp>
35 #include <RCF/ThreadLibrary.hpp>
36 #include <RCF/Token.hpp>
37 #include <RCF/TypeTraits.hpp>
48 typedef boost::shared_ptr<StubEntry> StubEntryPtr;
49 typedef boost::shared_ptr<StubFactory> StubFactoryPtr;
50 typedef boost::shared_ptr<TokenMapped> TokenMappedPtr;
52 class RCF_EXPORT StubFactoryRegistry
56 StubFactoryRegistry();
60 template<
typename I1,
typename ImplementationT>
61 bool bind(
const std::string &name_ =
"")
63 return bind( (I1 *) NULL, (ImplementationT **) NULL, name_);
66 template<
typename I1,
typename I2,
typename ImplementationT>
67 bool bind(
const std::string &name_ =
"")
69 return bind( (I1 *) NULL, (I2 *) NULL, (ImplementationT **) NULL, name_);
72 template<
typename I1,
typename I2,
typename I3,
typename ImplementationT>
73 bool bind(
const std::string &name_ =
"")
75 return bind( (I1 *) NULL, (I2 *) NULL, (I3 *) NULL, (ImplementationT **) NULL, name_);
78 template<
typename I1,
typename I2,
typename I3,
typename I4,
typename ImplementationT>
79 bool bind(
const std::string &name_ =
"")
81 return bind( (I1 *) NULL, (I2 *) NULL, (I3 *) NULL, (I4 *) NULL, (ImplementationT **) NULL, name_);
84 template<
typename I1,
typename ImplementationT>
85 bool bind(I1 *, ImplementationT **,
const std::string &name_ =
"")
87 const std::string &name = (name_ ==
"") ?
88 getInterfaceName((I1 *) NULL) :
91 StubFactoryPtr stubFactoryPtr(
92 new RCF::StubFactory_1<ImplementationT, I1>());
95 return insertStubFactory(name, desc, stubFactoryPtr);
98 template<
typename I1,
typename I2,
typename ImplementationT>
99 bool bind(I1 *, I2 *, ImplementationT **,
const std::string &name_ =
"")
101 const std::string &name = (name_ ==
"") ?
102 getInterfaceName((I1 *) NULL) :
105 StubFactoryPtr stubFactoryPtr(
106 new RCF::StubFactory_2<ImplementationT, I1, I2>());
109 return insertStubFactory(name, desc, stubFactoryPtr);
112 template<
typename I1,
typename I2,
typename I3,
typename ImplementationT>
113 bool bind(I1 *, I2 *, I3 *, ImplementationT **,
const std::string &name_ =
"")
115 const std::string &name = (name_ ==
"") ?
116 getInterfaceName((I1 *) NULL) :
119 StubFactoryPtr stubFactoryPtr(
120 new RCF::StubFactory_3<ImplementationT, I1, I2, I3>());
123 return insertStubFactory(name, desc, stubFactoryPtr);
126 template<
typename I1,
typename I2,
typename I3,
typename I4,
typename ImplementationT>
127 bool bind(I1 *, I2 *, I3 *, I4 *, ImplementationT **,
const std::string &name_ =
"")
129 const std::string &name = (name_ ==
"") ?
130 getInterfaceName((I1 *) NULL) :
133 StubFactoryPtr stubFactoryPtr(
134 new RCF::StubFactory_4<ImplementationT, I1, I2, I3, I4>());
137 return insertStubFactory(name, desc, stubFactoryPtr);
142 bool insertStubFactory(
143 const std::string &objectName,
144 const std::string &desc,
145 StubFactoryPtr stubFactoryPtr);
147 bool removeStubFactory(
148 const std::string &objectName);
150 StubFactoryPtr getStubFactory(
151 const std::string &objectName);
157 StubFactoryPtr> StubFactoryMap;
159 ReadWriteMutex mStubFactoryMapMutex;
160 StubFactoryMap mStubFactoryMap;
164 class RCF_EXPORT ObjectFactoryService :
166 public StubFactoryRegistry,
171 ObjectFactoryService();
174 boost::int32_t CreateObject(
const std::string &objectName, Token &token);
175 boost::int32_t DeleteObject(
const Token &token);
177 boost::int32_t addObject(TokenMappedPtr tokenMappedPtr, Token &token);
179 boost::int32_t CreateSessionObject(
const std::string &objectName);
180 boost::int32_t DeleteSessionObject();
182 StubEntryPtr getStubEntryPtr(
const Token &token);
183 TokenMappedPtr getTokenMappedPtr(
const Token & token);
186 void onServiceAdded(RcfServer &server);
187 void onServiceRemoved(RcfServer &server);
188 void onServerStart(RcfServer &);
189 void onServerStop(RcfServer &);
191 void cycleCleanup(
int timeoutMs);
192 void cleanupStubMap(
unsigned int timeoutS);
198 TokenMappedPtr> > StubMap;
201 typedef boost::shared_ptr<TokenFactory> TokenFactoryPtr;
202 TokenFactoryPtr mTokenFactory;
204 unsigned int mClientStubTimeoutS;
205 Mutex mCleanupThresholdMutex;
206 Condition mCleanupThresholdCondition;
207 unsigned int mCleanupIntervalS;
208 float mCleanupThreshold;
210 ReadWriteMutex mStubMapMutex;
216 typedef boost::shared_ptr<ObjectFactoryService>
217 ObjectFactoryServicePtr;
221 #endif // ! INCLUDE_RCF_OBJECTFACTORYSERVICE_HPP