llservice.cpp

Go to the documentation of this file.
00001 
00033 #include "linden_common.h"
00034 #include "llservice.h"
00035 
00036 LLService::creators_t LLService::sCreatorFunctors;
00037 
00038 LLService::LLService()
00039 {
00040 }
00041 
00042 LLService::~LLService()
00043 {
00044 }
00045 
00046 // static
00047 bool LLService::registerCreator(const std::string& name, creator_t fn)
00048 {
00049         llinfos << "LLService::registerCreator(" << name << ")" << llendl;
00050         if(name.empty())
00051         {
00052                 return false;
00053         }
00054 
00055         creators_t::value_type vt(name, fn);
00056         std::pair<creators_t::iterator, bool> rv = sCreatorFunctors.insert(vt);
00057         return rv.second;
00058 
00059         // alternately...
00060         //std::string name_str(name);
00061         //sCreatorFunctors[name_str] = fn;
00062 }
00063 
00064 // static
00065 LLIOPipe* LLService::activate(
00066         const std::string& name,
00067         LLPumpIO::chain_t& chain,
00068         LLSD context)
00069 {
00070         if(name.empty())
00071         {
00072                 llinfos << "LLService::activate - no service specified." << llendl;
00073                 return NULL;
00074         }
00075         creators_t::iterator it = sCreatorFunctors.find(name);
00076         LLIOPipe* rv = NULL;
00077         if(it != sCreatorFunctors.end())
00078         {
00079                 if((*it).second->build(chain, context))
00080                 {
00081                         rv = chain[0].get();
00082                 }
00083                 else
00084                 {
00085                         // empty out the chain, because failed service creation
00086                         // should just discard this stuff.
00087                         llwarns << "LLService::activate - unable to build chain: " << name
00088                                         << llendl;
00089                         chain.clear();
00090                 }
00091         }
00092         else
00093         {
00094                 llwarns << "LLService::activate - unable find factory: " << name
00095                                 << llendl;
00096         }
00097         return rv;
00098 }
00099 
00100 // static
00101 bool LLService::discard(const std::string& name)
00102 {
00103         if(name.empty())
00104         {
00105                 return false;
00106         }
00107         creators_t::iterator it = sCreatorFunctors.find(name);
00108         if(it != sCreatorFunctors.end())
00109         {
00110                 //(*it).second->discard();
00111                 sCreatorFunctors.erase(it);
00112                 return true;
00113         }
00114         return false;
00115 }
00116 

Generated on Fri May 16 08:32:30 2008 for SecondLife by  doxygen 1.5.5