void ClientHelperGenerator::structStart(const Poco::CppParser::Struct* pStruct, const CodeGenerator::Properties& properties) { AbstractGenerator::structStart(pStruct, properties); // add constructor/destructor Poco::CppParser::Function* pConstr = new Poco::CppParser::Function(_pStruct->name(), _pStruct); pConstr->setAccess(Poco::CppParser::Symbol::ACC_PUBLIC); pConstr->addDocumentation( " Creates a " + _pStruct->name() + "."); Poco::CppParser::Function* pDestr = new Poco::CppParser::Function(std::string("~")+_pStruct->name(), _pStruct); pDestr->setAccess(Poco::CppParser::Symbol::ACC_PUBLIC); pDestr->addDocumentation( " Destroys the " + _pStruct->name() + "."); // add a method TestProject::IMyClass::Ptr find(const std::string& uri) std::string iName (InterfaceGenerator::generateClassName(pStruct)); Poco::CppParser::Function* pFind = new Poco::CppParser::Function("static " + iName + "::Ptr find", _pStruct); pFind->makeInline(); pFind->addDocumentation(" Return an interface for the service object identified by the given URI."); pFind->addDocumentation(""); pFind->addDocumentation(" Depending on whether the service object has been registered on the same ORB, or not,"); pFind->addDocumentation(" the ORB will either return a RemoteObject (with forwards calls locally, without the"); pFind->addDocumentation(" need for serialization/deserialization), or a Proxy."); pFind->addDocumentation(""); pFind->addDocumentation(" The URI must have the following format: <scheme>://<authority>/<protocol>/<typeId>/<objectId>"); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("const std::string& uri", 0); pFind->addParameter(pParam1); pFind = new Poco::CppParser::Function(iName + "::Ptr findImpl", _pStruct); pFind->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE); pParam1= new Poco::CppParser::Parameter("const std::string& uri", 0); pFind->addParameter(pParam1); pFind = new Poco::CppParser::Function("static " + iName + "::Ptr find", _pStruct); pFind->makeInline(); pFind->addDocumentation(" Return a Proxy for the service object identified by the given URI."); pFind->addDocumentation(""); pFind->addDocumentation(" The given protocol name is used to determine the Transport used by"); pFind->addDocumentation(" the Proxy. This is used for objects identified by URIs that do not"); pFind->addDocumentation(" follow the standard Remoting URI structure."); pParam1= new Poco::CppParser::Parameter("const std::string& uri", 0); Poco::CppParser::Parameter* pParam2= new Poco::CppParser::Parameter("const std::string& protocol", 0); pFind->addParameter(pParam1); pFind->addParameter(pParam2); pFind = new Poco::CppParser::Function(iName + "::Ptr findImpl", _pStruct); pFind->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE); pParam1= new Poco::CppParser::Parameter("const std::string& uri", 0); pParam2= new Poco::CppParser::Parameter("const std::string& protocol", 0); pFind->addParameter(pParam1); pFind->addParameter(pParam2); _cppGen.addIncludeFile("Poco/RemotingNG/Identifiable.h"); _cppGen.addIncludeFile("Poco/RemotingNG/ORB.h"); Poco::CppParser::Variable* pVar = new Poco::CppParser::Variable("Poco::RemotingNG::ORB* _pORB", _pStruct); pVar->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE); // the src file will need most includes: for generated RemoteObject+ ProxyFactory, + "Net/DNS.h" std::string proxyFactName = ProxyFactoryGenerator::generateQualifiedClassName(nameSpace(), pStruct); std::string iFullName (InterfaceGenerator::generateQualifiedClassName(nameSpace(), pStruct)); Poco::CppParser::NameSpace* pRoot = Poco::CppParser::NameSpace::root(); const Poco::CppParser::Struct* pPF = dynamic_cast <const Poco::CppParser::Struct*>(pRoot->lookup(proxyFactName)); const Poco::CppParser::Struct* pI = dynamic_cast <const Poco::CppParser::Struct*>(pRoot->lookup(iFullName)); poco_check_ptr (pPF); poco_check_ptr (pI); Poco::CodeGeneration::Utility::handleInclude(pI, _cppGen); Poco::CodeGeneration::Utility::handleSrcInclude(pPF, _cppGen); _cppGen.addSrcIncludeFile("Poco/SingletonHolder.h"); // add a method static ClassNameHelper& instance(); Poco::CppParser::Function* pInstance = new Poco::CppParser::Function("static "+_pStruct->name()+"& instance", _pStruct); pInstance->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE); }
void BundleActivatorGenerator::structStart(const Poco::CppParser::Struct* pStruct, const CodeGenerator::Properties& properties) { // we don't care about pStruct, we only care about our service members! _pStruct = structClone(pStruct, _className, newBaseClasses(pStruct)); // member variables Poco::CppParser::Variable* pVar = new Poco::CppParser::Variable("std::vector<Poco::OSP::ServiceRef::Ptr> _services", _pStruct); pVar->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE); Poco::CppParser::Variable* pVar2 = new Poco::CppParser::Variable("std::set<std::string> _uris", _pStruct); pVar2->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE); Poco::CppParser::Variable* pVar3 = new Poco::CppParser::Variable("Poco::RemotingNG::ORB* _pORB", _pStruct); pVar3->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE); Poco::CppParser::Variable* pVar4 = new Poco::CppParser::Variable("std::set<std::string> _listeners", _pStruct); pVar4->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE); // methods // constructor { Poco::CppParser::Function* pConstr = new Poco::CppParser::Function(_pStruct->name(), _pStruct); pConstr->setAccess(Poco::CppParser::Symbol::ACC_PUBLIC); pConstr->addDocumentation(" Creates a " + _pStruct->name() + ". Initializes the bundle."); } //destructor { Poco::CppParser::Function* pDestr = new Poco::CppParser::Function(std::string("~")+_pStruct->name(), _pStruct); pDestr->setAccess(Poco::CppParser::Symbol::ACC_PUBLIC); pDestr->addDocumentation(" Destroys the " + _pStruct->name() + "."); } // void start(BundleContext::Ptr pContext) { Poco::CppParser::Function* pStart = new Poco::CppParser::Function("void start", _pStruct); pStart->addDocumentation(" Starts the services inside the bundle."); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); pStart->addParameter(pParam1); } // void stop(BundleContext::Ptr pContext) { Poco::CppParser::Function* pStop = new Poco::CppParser::Function("void stop", _pStruct); pStop->addDocumentation(" Stops the services inside the bundle."); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); pStop->addParameter(pParam1); } // Poco::RemotingNG::ORB& orb() { Poco::CppParser::Function* pORB = new Poco::CppParser::Function("Poco::RemotingNG::ORB& orb", _pStruct); pORB->addDocumentation(" Returns a reference to the Remoting ORB."); } //protected: //server methods: add always { // std::pair<std::string, Poco::OSP::ServiceRef::Ptr> // registerRemoteService(BundleContext::Ptr pContext, Poco::OSP::Service::Ptr pService, const std::string& listener, const std::string& serviceName, Poco::OSP::Properties props = Poco::OSP::Properties()) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("std::pair<std::string, Poco::OSP::ServiceRef::Ptr> registerRemoteService", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Registers the service with the ORB and at the ServiceRegistry the bundle. Returns the Remoting URI and the serviceRef."); Poco::CppParser::Parameter* pParam0= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("Poco::OSP::Service::Ptr pService", 0); Poco::CppParser::Parameter* pParam2= new Poco::CppParser::Parameter("const std::string& listener", 0); Poco::CppParser::Parameter* pParam3= new Poco::CppParser::Parameter("const std::string& serviceName", 0); Poco::CppParser::Parameter* pParam4= new Poco::CppParser::Parameter("Poco::OSP::Properties props = Poco::OSP::Properties()", 0); pReg->addParameter(pParam0); pReg->addParameter(pParam1); pReg->addParameter(pParam2); pReg->addParameter(pParam3); pReg->addParameter(pParam4); } // std::string registerRemoteObject(Poco::RemotingNG::RemoteObject::Ptr pObj, const std::string& listener) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("std::string registerRemoteObject", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Registers the service with the ORB only. Returns the Remoting URI for the remote object."); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("Poco::RemotingNG::RemoteObject::Ptr pObj", 0); Poco::CppParser::Parameter* pParam2= new Poco::CppParser::Parameter("const std::string& listener", 0); pReg->addParameter(pParam1); pReg->addParameter(pParam2); } // std::string registerListener(Listener::Ptr pListener) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("std::string registerListener", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Registers the listener at the ORB. Returns the id of the endpoint. listener will be automatically unregistered with bundle stop"); Poco::CppParser::Parameter* pParam1 = new Poco::CppParser::Parameter("Poco::RemotingNG::Listener::Ptr pListener", 0); pReg->addParameter(pParam1); } // Poco::OSP::ServiceRef::Ptr registerService(Poco::OSP::BundleContext::Ptr pContext, const std::string& serviceName, Poco::OSP::Service::Ptr pService, Poco::OSP::Properties props = Poco::OSP::Properties()) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("Poco::OSP::ServiceRef::Ptr registerService", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Registers the service at the serviceRegistry only. Stores the serviceRef for auto unregister"); Poco::CppParser::Parameter* pParam0= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("const std::string& serviceName", 0); Poco::CppParser::Parameter* pParam2= new Poco::CppParser::Parameter("Poco::OSP::Service::Ptr pService", 0); Poco::CppParser::Parameter* pParam3= new Poco::CppParser::Parameter("Poco::OSP::Properties props = Poco::OSP::Properties()", 0); pReg->addParameter(pParam0); pReg->addParameter(pParam1); pReg->addParameter(pParam2); pReg->addParameter(pParam3); } // void unregisterRemoteService(Poco::OSP::BundleContext::Ptr pContext, const std::string& uri, Poco::OSP::ServiceRef::Ptr pService) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("void unregisterRemoteService", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Unregisters the service at the ORB and at the ServiceRegistry."); Poco::CppParser::Parameter* pParam0= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("const std::string& uri", 0); Poco::CppParser::Parameter* pParam2= new Poco::CppParser::Parameter("Poco::OSP::ServiceRef::Ptr pService", 0); pReg->addParameter(pParam0); pReg->addParameter(pParam1); pReg->addParameter(pParam2); } // void unregisterRemoteObject(const std::string& uri) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("void unregisterRemoteObject", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Unregisters the service at the ORB only."); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("const std::string& uri", 0); pReg->addParameter(pParam1); } // void unregisterService(Poco::OSP::BundleContext::Ptr pContext, Poco::OSP::ServiceRef::Ptr pService) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("void unregisterService", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Unregisters the service at the serviceRegistry only."); Poco::CppParser::Parameter* pParam0= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("Poco::OSP::ServiceRef::Ptr pService", 0); pReg->addParameter(pParam0); pReg->addParameter(pParam1); } // void unregisterListener(const std::string& listener) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("void unregisterListener", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Unregisters the listener at the ORB."); Poco::CppParser::Parameter* pParam1 = new Poco::CppParser::Parameter("const std::string& listener", 0); pReg->addParameter(pParam1); } // void unregisterAll(BundleContext::Ptr pContext) { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("void unregisterAll", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Unregisters all services and remoteobjects. Automatically called by stop method."); Poco::CppParser::Parameter* pParam1= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); pReg->addParameter(pParam1); } //void setupRemotingOSP() { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("void setupRemotingOSP", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Initializes skeletons, proxyfactories and servicefactories."); Poco::CppParser::Parameter* pParam0= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); pReg->addParameter(pParam0); } //void shutdownRemotingOSP() { Poco::CppParser::Function* pReg = new Poco::CppParser::Function("void shutdownRemotingOSP", _pStruct); pReg->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED); pReg->addDocumentation(" Deinitializes skeletons, proxyfactories and servicefactories for this bundle."); Poco::CppParser::Parameter* pParam0= new Poco::CppParser::Parameter("Poco::OSP::BundleContext::Ptr pContext", 0); pReg->addParameter(pParam0); } // includes _cppGen.addIncludeFile("Poco/OSP/ServiceRef.h"); _cppGen.addIncludeFile("Poco/RemotingNG/ORB.h"); _cppGen.addSystemIncludeFile("vector"); _cppGen.addSystemIncludeFile("set"); _cppGen.addSystemIncludeFile("algorithm"); } // _serverMode // includes _cppGen.addIncludeFile("Poco/OSP/BundleActivator.h"); _cppGen.addIncludeFile("Poco/OSP/ServiceRef.h"); _cppGen.addIncludeFile("Poco/RemotingNG/Identifiable.h"); // src includes // we need to register the proxyfactories for all structs std::vector<BundleService>::const_iterator it = _services.begin(); Poco::CppParser::NameSpace* pRoot = Poco::CppParser::NameSpace::root(); for (; it != _services.end(); ++it) { if (it->clientCode) { std::string fullName = ProxyFactoryGenerator::generateQualifiedClassName(nameSpace(), it->pStruct); const Poco::CppParser::Struct* pF = dynamic_cast <const Poco::CppParser::Struct*>(pRoot->lookup(fullName)); if (!pF) throw Poco::NotFoundException("didn't find proxyfactory for class " + it->pStruct->fullName()); Poco::CodeGeneration::Utility::handleSrcInclude(pF, _cppGen); } if (it->serverCode) { std::string fullName = SkeletonGenerator::generateQualifiedClassName(nameSpace(), it->pStruct); const Poco::CppParser::Struct* pF = dynamic_cast <const Poco::CppParser::Struct*>(pRoot->lookup(fullName)); if (!pF) throw Poco::NotFoundException("didn't find skeleton for class " + it->pStruct->fullName()); Poco::CodeGeneration::Utility::handleSrcInclude(pF, _cppGen); } } _cppGen.addSrcIncludeFile("Poco/RemotingNG/URIUtility.h"); _cppGen.addSrcIncludeFile("Poco/RemotingNG/RemoteObject.h"); _cppGen.addSrcIncludeFile("Poco/OSP/OSPException.h"); _cppGen.addSrcIncludeFile("Poco/OSP/ServiceRegistry.h"); _cppGen.addSrcIncludeFile("Poco/ClassLibrary.h"); }