void RemoteObjectGenerator::structStart(const Poco::CppParser::Struct* pStruct, const CodeGenerator::Properties& properties)
{
	AbstractGenerator::structStart(pStruct, properties);
	_codeInjectors.clear();
	// add constructor/destructor
	Poco::CppParser::Function* pConstr = new Poco::CppParser::Function(_pStruct->name(), _pStruct);
	//const Identifiable::ObjectId& oid
	Poco::CppParser::Parameter* pParam1 = new Poco::CppParser::Parameter("const Poco::RemotingNG::Identifiable::ObjectId& oid", pConstr);
	Poco::CppParser::Parameter* pParam2 = new Poco::CppParser::Parameter("Poco::SharedPtr<" + pStruct->fullName() + "> pServiceObject", pConstr);
	pConstr->addParameter(pParam1);
	pConstr->addParameter(pParam2);

	pConstr->addDocumentation(	" Creates a " + _pStruct->name() + ".");

	Poco::CppParser::Function* pDestr = new Poco::CppParser::Function(std::string("virtual ~")+_pStruct->name(), _pStruct);
	pDestr->addDocumentation(	" Destroys the " + _pStruct->name() + ".");

	Poco::CppParser::TypeDef* pTypeDef = new Poco::CppParser::TypeDef("typedef Poco::AutoPtr<" + generateClassName(pStruct) + "> Ptr", _pStruct);
	poco_check_ptr (pTypeDef); // just avoid unused variable warning

	// adds the member var
	_cppGen.addIncludeFile("Poco/SharedPtr.h");
	_cppGen.addIncludeFile("Poco/RemotingNG/RemoteObject.h");
	_cppGen.addIncludeFile("Poco/RemotingNG/Identifiable.h");
	Poco::CppParser::Variable* pVar = new Poco::CppParser::Variable("Poco::SharedPtr<" + pStruct->fullName() + "> _pServiceObject", _pStruct);
	pVar->setAccess(Poco::CppParser::Symbol::ACC_PRIVATE);
	// add a method virtual const Poco::RemotingNG::Identifiable::TypeId& remoting__typeId() const
	Poco::CppParser::Function* pTypeId = new Poco::CppParser::Function("virtual const Poco::RemotingNG::Identifiable::TypeId& remoting__typeId", _pStruct);
	pTypeId->makeConst();
	pTypeId->makeInline();

	if (GenUtility::hasEvents(pStruct))
	{
		Poco::CppParser::Function* pEvents = new Poco::CppParser::Function("virtual std::string remoting__enableEvents", _pStruct);
		Poco::CppParser::Parameter* pParam = new Poco::CppParser::Parameter("Poco::RemotingNG::Listener::Ptr pListener", 0);
		pEvents->addParameter(pParam);
		pParam = new Poco::CppParser::Parameter("bool enable = true", 0);
		pEvents->addParameter(pParam);

		Poco::CppParser::Function* pHasEvents = new Poco::CppParser::Function("virtual bool remoting__hasEvents", _pStruct);
		pHasEvents->makeConst();

		Poco::CppParser::Function* pRemoteEvents = new Poco::CppParser::Function("virtual void remoting__enableRemoteEvents", _pStruct);
		pParam = new Poco::CppParser::Parameter("const std::string& protocol", 0);
		pRemoteEvents->addParameter(pParam);

		std::string inc = Utility::createInclude(_pStruct, _cppGen.usePocoIncludeStyle());
		Poco::replaceInPlace(inc, "RemoteObject", "EventDispatcher");
		_cppGen.addSrcIncludeFile(inc);
	}

	handleParentFunctions(_pStructIn);
	checkForEventMembers(pStruct);
}
예제 #2
0
Poco::CppParser::Variable* XSDGenerator::createVariable(const Poco::CppParser::Parameter* pParam, Poco::CppParser::Struct* pStruct)
{
	// a variable is always a non const, non-ref, non-pointer
	std::string decl(pParam->declType());
	if (pParam->isPointer())
		decl.append("*");
	decl.append(" _");
	decl.append(pParam->name());
	Poco::CppParser::Variable* pRet = new Poco::CppParser::Variable(decl, pStruct);
	pRet->setAccess(Poco::CppParser::Variable::ACC_PRIVATE);
	return pRet;
}
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");
}
예제 #6
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);
			}
		}
			
	}
}
예제 #7
0
Poco::CppParser::Struct* XSDGenerator::convertToStruct(const Poco::CppParser::Function* pFunc, bool isResponse)
{
	/// a type created by function parameters can never extend any other type
	std::string inputDataType;
	if (isResponse)
		inputDataType = GenUtility::getReplyMethodName(pFunc);
	else
		inputDataType = GenUtility::getRequestMethodName(pFunc);
	
	std::string decl(Poco::CodeGeneration::Utility::CLASS);
	decl.append(" ");
	decl.append(inputDataType);

	Poco::CppParser::Struct* pStruct = new Poco::CppParser::Struct(decl, true, &_ns);
	
	// now add for each param a set and get method,
	// also add a variable for each param (set the docu!!!!)
	// don't forget the return value!
	// return parameter
	std::string rdecl = pFunc->getReturnParameter();
	if (!rdecl.empty() && rdecl != "void" && isResponse)
	{
		// if we have an inline type we must fetch the struct for that type
		// and add all children of that type as direct members of pStruct
		// or simply inherit from it :-)
		bool isInline = GenUtility::getInlineReturnParam(pFunc);
		if (isInline)
		{
			std::string fullResType = GenUtility::getResolvedReturnParameterType(pFunc->nameSpace(), pFunc);
			std::string resType(fullResType);
			//restype can either be a native type or a complex type which we serialize, or it can be hidden inside a template like vector, set,... SharedPtr
			bool isPtrType = GenUtility::isPtrType(resType);
			if (isPtrType)
			{
				std::vector<std::string> inn = GenUtility::getInnerTemplateTypes(resType);
				poco_assert (inn.size() == 1);
				resType = inn[0];
			}
			bool isVectorOrNullable = GenUtility::isVectorType(resType) || GenUtility::isNullableType(resType) || GenUtility::isOptionalType(resType);
			if (isVectorOrNullable)
			{
				throw Poco::LogicException(pFunc->fullName() + ": For an inlined data type maxOccurs must be 1! No vector/set/multiset allowed");
			}
			if (AbstractGenerator::BUILTIN_TYPES.find(resType) != AbstractGenerator::BUILTIN_TYPES.end())
			{
				throw Poco::LogicException(pFunc->fullName() + ": Only complex data types can be inlined!");
			}

			// now get the class definition for that file
			Poco::CppParser::Symbol* pSym = pFunc->nameSpace()->lookup(resType);
			if (pSym && pSym->kind() == Poco::CppParser::Symbol::SYM_STRUCT)
			{
				Poco::CppParser::Struct* pRetStruct = static_cast<Poco::CppParser::Struct*>(pSym);
				// deep copy members pRetStruct
				deepCopyMembers(pRetStruct, pStruct);
			}
			else
				throw Poco::LogicException("Failed to find data type for inlined return value in method: " + pFunc->fullName());
		}
		else
		{
			std::string retParamName (GenUtility::getReturnParameterName(pFunc));
			rdecl.append(" " + retParamName);
			Poco::CppParser::Parameter p(rdecl, 0);
			Poco::CppParser::Variable* pVar = createVariable(&p, pStruct);
			Poco::CppParser::Attributes attr;
			attr["order"] = "0";
			pVar->setAttributes(attr);
			//pVar->setDocumentation("///[[order=0]]");
			createGetFct(&p, pStruct);
			createSetFct(&p, pStruct);
		}
	}
	Poco::CppParser::Function::Iterator it = pFunc->begin();
	Poco::CppParser::Function::Iterator itEnd = pFunc->end();
	Poco::UInt32 unknownOrderOffset = 0xffff0000;
	CodeGenerator::Properties funcProps;
	GeneratorEngine::parseProperties(pFunc, funcProps);
	for (; it != itEnd; ++it)
	{
		std::string direction;
		CodeGenerator::Properties::iterator itProp = funcProps.find("$" + (*it)->name());
		if (itProp != funcProps.end())
		{
			CodeGenerator::Properties paramProps; // we need direction
			GeneratorEngine::parseElementProperties(itProp->second, paramProps);
			GeneratorEngine::getStringProperty(paramProps, Utility::DIRECTION, direction);
		}
		
		//isOutParam excludes soapheader already, do the same for replies
		bool inSoapHeader = GenUtility::getIsInHeader(pFunc, *it);
		if ( (isResponse && isOutParameter(*it) && direction != "in") || (!isResponse && !inSoapHeader && direction != "out"))
		{
			Poco::CppParser::Variable* pVar = createVariable(*it, pStruct);
			addVarDocu(pVar, pFunc, (*it)->name(), unknownOrderOffset++);
			createGetFct(*it, pStruct);
			createSetFct(*it, pStruct);
		}
		else if (inSoapHeader)
		{
			// Note: we must export for each soapHeader an element that has the same name as the parameter!
			Poco::CppParser::Parameter* pParam = *it;
			const std::string& declType = pParam->declType();
			std::string name = GenUtility::getParameterName(pFunc, pParam);
			std::string aType = Poco::CodeGeneration::Utility::resolveType(pFunc->nameSpace(), declType);
			if (aType == declType)
			{
				_exportSoapHeaderTypes.insert (std::make_pair(name, aType));
			}
			else
			{
				Poco::CppParser::Symbol* pSym = pFunc->nameSpace()->lookup(aType);
				poco_assert (pSym);
				_exportSoapHeaderTypes.insert (std::make_pair(name, pSym->name()));
			}
		}
	}
	return pStruct;
}