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::Function* XSDGenerator::createGetFct(const Poco::CppParser::Parameter* pParam, Poco::CppParser::Struct* pStruct)
{
	std::string methodName("get");
	methodName.append(pParam->name());
	methodName[3] = (char)std::toupper(methodName[3]);

	// we return either by value or by const &
	std::string decl(createParameterTypeDecl(pParam->declType()));
	decl.append(" ");
	decl.append(methodName);
	Poco::CppParser::Function* pFct = new Poco::CppParser::Function(decl, pStruct);
	pFct->makeConst();
	pFct->makeInline();

	return pFct;
}
void RemoteObjectGenerator::methodStart(const Poco::CppParser::Function* pFuncOld, const CodeGenerator::Properties& properties)
{
	if (_functions.find(pFuncOld->name()) != _functions.end())
		return;
	_functions.insert(pFuncOld->name());
	Poco::CppParser::Function* pFunc = methodClone(pFuncOld, properties);
	pFunc->makeInline(); // impl is just one single line
	Poco::CodeGeneration::CodeGenerator::Properties::const_iterator itSync = properties.find(Poco::CodeGeneration::Utility::SYNCHRONIZED);
	if (itSync != properties.end() && (itSync->second == Utility::VAL_TRUE || itSync->second.empty() || itSync->second == "all" || itSync->second == "remote"))
	{
		_codeInjectors.insert(std::make_pair(pFunc->name(), &RemoteObjectGenerator::syncFwdCodeGen));
	}
	else
	{
		_codeInjectors.insert(std::make_pair(pFunc->name(), &RemoteObjectGenerator::fwdCodeGen));
	}
}
Пример #4
0
Poco::CppParser::Function* XSDGenerator::createSetFct(const Poco::CppParser::Parameter* pParam, Poco::CppParser::Struct* pStruct)
{
	std::string methodName("set");
	methodName.append(pParam->name());
	methodName[3] = (char)std::toupper(methodName[3]);

	// we return either by value or by const &
	std::string decl("void ");
	decl.append(methodName);
	Poco::CppParser::Function* pFct = new Poco::CppParser::Function(decl, pStruct);
	pFct->makeInline();
	// add the one parameter
	Poco::CppParser::Parameter* pParam2 = createParameter(pParam, pFct);
	pFct->addParameter(pParam2);

	return pFct;
}
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);
}