Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

serviceprovider.cpp

Go to the documentation of this file.
00001 
00002 #include <kore/version.h>
00003 #include <kore/serviceprovider.h>
00004 #include <kore/servicemanager.h>
00005 #include <kore/kernel.h>
00006 #include <iostream>
00007 
00008 using namespace kore;
00009 
00010 ServiceProvider::Service::Service(ServiceProvider* provider,const char* name,const char* description)
00011 {
00012     _provider = provider;
00013     _name = name;
00014     _description = description;
00015     _parent = 0;
00016     string srv(name);
00017     unsigned i = 0;
00018     unsigned j = 0;
00019     // split the string into pieces
00020     while( j < srv.size() )
00021     {
00022         j = srv.find('/',i);
00023         if( srv[j] == '/' )
00024         {
00025             _path.push_back(string(srv, i, j - i));
00026 //            cout << string(srv, i, j-i) << "/\n";
00027         }
00028         else
00029         {
00030             _leaf = string(srv, i, j-i);
00031 //            cout << string(srv, i, j-1) << endl;
00032         }
00033         i = j+1;
00034     }
00035 //        cout << "============\n";
00036 }
00037 ServiceProvider* ServiceProvider::Service::provider() const
00038 {
00039     return _provider;
00040 }
00041 const char* ServiceProvider::Service::name() const
00042 {
00043     return _name;
00044 }
00045 ServiceProvider::Service::operator const char* () const
00046 {
00047     return _name;
00048 }
00049 const char* ServiceProvider::Service::description() const
00050 {
00051     return _description;
00052 }
00053 
00054 ServiceProvider::ServiceProvider()
00055 {
00056 }
00057 ServiceProvider::ServiceProvider(const Info* info):Module(info)
00058 {
00059 }
00060 ServiceProvider::~ServiceProvider()
00061 {
00062 }
00063 
00064 void ServiceProvider::addService(const ServiceProvider::Service* service)
00065 {
00066     _services.push_back(service);
00067 }
00068 
00069 const ServiceProvider::Service** ServiceProvider::services() const
00070 {
00071     int n = _services.size();
00072     const Service** srv = new const Service*[n+1];
00073     int i;
00074     for( i = 0; i < n; i++ )
00075         srv[i] = _services[i];
00076     srv[i] = 0;
00077     return srv;
00078 }
00079 
00080 const ServiceProvider::Service* ServiceProvider::service(const char* srv) const
00081 {
00082     if( !srv )
00083         return 0;
00084     Service serv(0, srv, 0);
00085     return service(&serv);
00086 }
00087 
00088 const ServiceProvider::Service* ServiceProvider::service(const Service* srv) const
00089 {
00090     if( !srv )
00091         return 0;
00092     const Service* serv = 0;
00093     serv = passiveService(srv);
00094     if( serv )
00095         return serv;
00096     else
00097         return activeService(srv);
00098 }
00099 
00100 const ServiceProvider::Service* ServiceProvider::passiveService(const Service* srv) const
00101 {
00102     // paranoia
00103     if( !srv )
00104         return 0;
00105     const Service* res = 0;
00106     const Service** srvs = services();
00107     for(int i=0; srvs[i]; i++)
00108         if( (srvs[i] == srv) || ( strcmp(srvs[i]->name(),srv->name()) == 0 ) )
00109         {
00110             res = srvs[i];
00111             break;
00112         }
00113     delete[] srvs;
00114     return res;
00115 }
00116 
00117 const ServiceProvider::Service* ServiceProvider::activeService(const Service* srv) const
00118 {
00119     return 0;
00120 }
00121 
00122 void ServiceProvider::registeringProvider(ServiceManager* sm)
00123 {
00124     //cout << info()->name() << " " << (const char*)*(info()->version()) << " : registering to " << sm->info()->name() << " " << (const char*)*(sm->info()->version()) << endl;
00125 }
00126 void ServiceProvider::providerRegistered(ServiceManager* sm)
00127 {
00128     //cout << info()->name() << " " << (const char*)*(info()->version()) << " : registered to " << sm->info()->name() << " " << (const char*)*(sm->info()->version()) << endl;
00129 }
00130 void ServiceProvider::unregisteringProvider(ServiceManager* sm)
00131 {
00132     //cout << info()->name() << " " << (const char*)*(info()->version()) << " : unregistering from " << sm->info()->name() << " " << (const char*)*(sm->info()->version()) << endl;
00133 }
00134 void ServiceProvider::providerUnregistered(ServiceManager* sm)
00135 {
00136     //cout << info()->name() << " " << (const char*)*(info()->version()) << " : unregistered from " << sm->info()->name() << " " << (const char*)*(sm->info()->version()) << endl;
00137 }
00138 
00139 void ServiceProvider::registeringService(ServiceManager* sm,const Service* srv)
00140 {
00141     //cout << info()->name() << " " << (const char*)*(info()->version()) << " : registering service " << srv->name() << " (" << srv->description() << ") to " << sm->info()->name() << " " << (const char*)*(sm->info()->version()) << endl;
00142 }
00143 void ServiceProvider::serviceRegistered(ServiceManager* sm,const Service* srv)
00144 {
00145     //cout << info()->name() << " " << (const char*)*(info()->version()) << " : registered service " << srv->name() << " (" << srv->description() << ") to " << sm->info()->name() << " " << (const char*)*(sm->info()->version()) << endl;
00146 }
00147 void ServiceProvider::unregisteringService(ServiceManager* sm,const Service* srv)
00148 {
00149     //cout << info()->name() << " " << (const char*)*(info()->version()) << " : unregistering service " << srv->name() << " (" << srv->description() << ") from " << sm->info()->name() << " " << (const char*)*(sm->info()->version()) << endl;
00150 }
00151 void ServiceProvider::serviceUnregistered(ServiceManager* sm,const Service* srv)
00152 {
00153     //cout << info()->name() << " " << (const char*)*(info()->version()) << " : unregistered service " << srv->name() << " (" << srv->description() << ") from " << sm->info()->name() << " " << (const char*)*(sm->info()->version()) << endl;
00154 }

Generated on Sat Feb 16 13:34:29 2002 for Korelib by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001