00001 00034 #ifndef LL_LLSERVICE_H 00035 #define LL_LLSERVICE_H 00036 00037 #include <string> 00038 #include <map> 00039 //#include <boost/intrusive_ptr.hpp> 00040 //#include <boost/shared_ptr.hpp> 00041 00042 //#include "llframetimer.h" 00043 #include "lliopipe.h" 00044 #include "llchainio.h" 00045 00046 #if 0 00047 class LLServiceCreator; 00051 namespace boost 00052 { 00053 void intrusive_ptr_add_ref(LLServiceCreator* p); 00054 void intrusive_ptr_release(LLServiceCreator* p); 00055 }; 00056 #endif 00057 00067 #if 0 00068 class LLServiceCreator 00069 { 00070 public: 00071 typedef boost::intrusive_ptr<LLService> service_t; 00072 virtual ~LLServiceCreator() {} 00073 virtual service_t activate() = 0; 00074 virtual void discard() = 0; 00075 00076 protected: 00077 LLServiceCreator() : mReferenceCount(0) 00078 { 00079 } 00080 00081 private: 00082 friend void boost::intrusive_ptr_add_ref(LLServiceCreator* p); 00083 friend void boost::intrusive_ptr_release(LLServiceCreator* p); 00084 U32 mReferenceCount; 00085 }; 00086 #endif 00087 00088 #if 0 00089 namespace boost 00090 { 00091 inline void intrusive_ptr_add_ref(LLServiceCreator* p) 00092 { 00093 ++p->mReferenceCount; 00094 } 00095 inline void intrusive_ptr_release(LLServiceCreator* p) 00096 { 00097 if(p && 0 == --p->mReferenceCount) 00098 { 00099 delete p; 00100 } 00101 } 00102 }; 00103 #endif 00104 00119 class LLService : public LLIOPipe 00120 { 00121 public: 00122 //typedef boost::intrusive_ptr<LLServiceCreator> creator_t; 00123 //typedef boost::intrusive_ptr<LLService> service_t; 00124 typedef boost::shared_ptr<LLChainIOFactory> creator_t; 00125 00134 static bool registerCreator(const std::string& name, creator_t fn); 00135 00144 static LLIOPipe* activate( 00145 const std::string& name, 00146 LLPumpIO::chain_t& chain, 00147 LLSD context); 00148 00155 static bool discard(const std::string& name); 00156 00157 protected: 00158 // The creation factory static data. 00159 typedef std::map<std::string, creator_t> creators_t; 00160 static creators_t sCreatorFunctors; 00161 00162 protected: 00163 // construction & destruction. since this class is an abstract 00164 // base class, it is up to Service implementations to actually 00165 // deal with construction and not a public method. How that 00166 // construction takes place will be handled by the service 00167 // creators. 00168 LLService(); 00169 virtual ~LLService(); 00170 00171 protected: 00172 // This frame timer records how long this service has 00173 // existed. Useful for derived services to give themselves a 00174 // lifetime and expiration. 00175 // *NOTE: Phoenix - This functionaity has been moved to the 00176 // pump. 2005-12-13 00177 //LLFrameTimer mTimer; 00178 00179 // Since services are designed in an 'ask now, respond later' 00180 // idiom which probably crosses thread boundaries, almost all 00181 // services will need a handle to a response pipe. It will usually 00182 // be the job of the service author to derive a useful 00183 // implementation of response, and up to the service subscriber to 00184 // further derive that class to do something useful when the 00185 // response comes in. 00186 LLIOPipe::ptr_t mResponse; 00187 }; 00188 00189 00190 #endif // LL_LLSERVICE_H