void RemoteObjectGenerator::checkForEventMembersImpl(const Poco::CppParser::Struct* pStruct)
{
	Poco::CppParser::NameSpace::SymbolTable tbl;
	pStruct->variables(tbl);
	Poco::CppParser::NameSpace::SymbolTable::const_iterator it = tbl.begin();
	Poco::CppParser::NameSpace::SymbolTable::const_iterator itEnd = tbl.end();
	for (; it != itEnd; ++it)
	{
		Poco::CppParser::Variable* pVar = static_cast<Poco::CppParser::Variable*>(it->second);
		const std::string& varType = pVar->declType();
		if (pVar->getAccess() == Poco::CppParser::Variable::ACC_PUBLIC && !(pVar->flags() & Poco::CppParser::Variable::VAR_STATIC))
		{
			if (varType.find("Poco::BasicEvent") == 0 || varType.find("Poco::FIFOEvent") == 0)
			{
				_hasEvents = true;
				_events.push_back(pVar->name());
				_cppGen.addSrcIncludeFile("Poco/RemotingNG/ORB.h");
				_cppGen.addSrcIncludeFile("Poco/Delegate.h");
				// generate a serializer method for that member too
				// call methodStart(const Poco::CppParser::Function* pFuncOld, const CodeGenerator::Properties& methodProperties)
				// convert the basicevent to a private function
				std::string funcDecl("void ");
				std::string fctName = generateEventFunctionName(pVar->name());
				funcDecl.append(fctName);
				std::vector<std::string> templTypes = GenUtility::getResolvedInnerTemplateTypes(pStruct, varType);
				if (templTypes.size() != 1)
					throw Poco::InvalidArgumentException("Illegal remote event param: " + pVar->fullName());
				std::string paramDecl = templTypes[0];
				if (paramDecl != "void")
				{
					paramDecl.append("& data");
				}
				Poco::CppParser::Function* pFunc = new Poco::CppParser::Function(funcDecl, _pStruct);
				pFunc->setAccess(Poco::CppParser::Symbol::ACC_PROTECTED);
				if (paramDecl != "void")
				{
					Poco::CppParser::Parameter* pParam = new Poco::CppParser::Parameter(paramDecl, 0);
					pFunc->addParameter(pParam);
				}
			}
		}
	}
}
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");
}
Exemplo n.º 4
0
void XSDGenerator::deepCopyMembers(const Poco::CppParser::Struct* pIn, Poco::CppParser::Struct* pOut)
{
	// deep copy all variables and functions, exluding constructor/destructor
	Poco::CppParser::Struct::BaseIterator itB = pIn->baseBegin();
	Poco::CppParser::Struct::BaseIterator itBEnd = pIn->baseEnd();
	for (; itB!= itBEnd; ++itB)
	{
		if (itB->pClass)
			deepCopyMembers(itB->pClass, pOut);
	}
	// handle members
	Poco::CppParser::NameSpace::SymbolTable members;
	pIn->variables(members);
	Poco::CppParser::NameSpace::SymbolTable::const_iterator it = members.begin();
	Poco::CppParser::NameSpace::SymbolTable::const_iterator itEnd = members.end();
	for (; it != itEnd; ++it)
	{
		Poco::CppParser::Variable* pVar = static_cast<Poco::CppParser::Variable*>(it->second);
		Poco::CppParser::Variable* pCpyVar = new Poco::CppParser::Variable(pVar->declaration(), pOut);
		pCpyVar->setAccess(pVar->getAccess());
		pCpyVar->setAttributes(pVar->getAttributes());
	}
	// handle methods
	members.clear();
	Poco::CppParser::Struct::Functions fcts;
	pIn->methods(Poco::CppParser::Symbol::ACC_PUBLIC, fcts);
	Poco::CppParser::Struct::Functions::const_iterator itt = fcts.begin();
	Poco::CppParser::Struct::Functions::const_iterator ittEnd = fcts.end();
	for (; itt != ittEnd; ++itt)
	{
		Poco::CppParser::Function* pFct = static_cast<Poco::CppParser::Function*>(*itt);
		if (!pFct->isConstructor() && ! pFct->isDestructor())
		{
			Poco::CppParser::Function* pCpyFct = new Poco::CppParser::Function(pFct->declaration(), pOut);
			pCpyFct->setAccess (pFct->getAccess());
			addDocumentation(pFct, pCpyFct);
			pCpyFct->setAttributes(pFct->getAttributes());
			if (pFct->isConst())
				pCpyFct->makeConst();

			Poco::CppParser::Function::Iterator itF = pFct->begin();
			Poco::CppParser::Function::Iterator itFEnd = pFct->end();

			for (; itF != itFEnd; ++itF)
			{
				std::string decl = Poco::CodeGeneration::Utility::resolveParamDecl(pIn, *itF);
				if ((*itF)->hasDefaultValue())
				{
					decl.append(" = ");
					decl.append(Poco::CodeGeneration::Utility::resolveType(_pStructIn, (*itF)->declType()));
					decl.append("(");
					decl.append((*itF)->defaultValue());
					decl.append(")");
				}
				
				Poco::CppParser::Parameter* pParam = new Poco::CppParser::Parameter(decl, pCpyFct);
				
				pCpyFct->addParameter(pParam);
			}
		}
			
	}
}