MARIE 0.4 TO 0.5
From MARIEWiki
Contents |
Assumptions
- MARIE 0.5 is correctly installed;
- The component to convert to MARIE 0.5 is a MARIE 0.4 component;
- The original source files are named :
- aaYourApplicationName.cpp;
- YourApplicationNameAdapterHandler.h;
- YourApplicationNameAdapterHandler.cpp;
- YourApplicationNameVisitorConfig.h;
- YourApplicationNameVisitorConfig.h;
- YourApplicationNameAdapterBuilder.h;
- YourApplicationNameAdapterBuilder.cpp.
Source files modification
Changes in Terminology
All core classes used to build components have been renamed to use the right terminology. So each time you see Adapter or adapter in the sources, it should be changed to Component or component.
Simplify the main
Delete the entire aaYourAdapterName.cpp main file and create a file like this one :
// MARIE include #include "MARIE.h" #include <ace/ACE.h> #include <ComponentHandlerQueueTask.h> #include <ComponentMain.h> #include <CommStrategyFactory.h> #include <SerDesFactory.h> #include <CFBFactory.h>
// YourComponentName include #include "YourComponentNameComponentHandler.h"
using namespace marie;
int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { (CFBFactory::getInstance()).loadCFBs(); (CommStrategyFactory::getInstance()).loadCommStrategies(); (SerDesFactory::getInstance()).loadSerDes();
YourComponentNameComponentHandler* componentHandler = new YourComponentNameComponentHandler(); ComponentHandlerTaskAbstract* componentHandlerTask = new ComponentHandlerQueueTask(*componentHandler); ComponentMain componentMain(argc, argv, *componentHandler, *componentHandlerTask); componentMain.execute(); }
Be carefull to use the proper include for YourComponentNameHandler and the correct type of component. In this example the component is a ComponentHandlerQueueTask.
Get rid of the builder
Delete the file YourApplicationNameAdapterBuilder.h and YourApplicationNameAdapterBuilder.cpp
Don't activate the port anymore
Usually, in YourComponentNameHandler::init() method, there is a section of code that activate the port that looks like this :
MARIE_TRY("YourComponentNameComponentHandler::init() -> Activating port");
bool succeeded = port->activate();
if(succeeded)
{
MARIE_SUCCEEDED();
}
else
{
MARIE_FAILED();
MARIE_INFO(ACE_TEXT("YourComponentNameComponentHandler::init() -> Unable to activate port %s"), port->getName().c_str());
}
Delete that segment of code for both input and output port initialization.
Properly quit the component
Depending of the type of component, the way to respond to the Quit event is slightly different.
For an ComponentHandlerIterateTask component:
bool YourComponentNameComponentHandler::quit()
{
ACE_Guard<ACE_Thread_Mutex> guard(m_mutex);
MARIE_DEBUG("YourComponentNameComponentHandler::quit()");
m_quitState = true;
return(true);
}
void YourComponentNameHandler::iterate()
{
if(m_quitState && m_owner != 0)
{
// Delete all memory
// Deactivate the component
m_owner->deactivate();
m_quitState = false;
}
// The rest of your code goes here
}
For an ComponentHandlerQueueTask component:
bool YourComponentNameComponentHandler::quit()
{
ACE_Guard<ACE_Thread_Mutex> guard(m_mutex);
MARIE_DEBUG("YourComponentNameComponentHandler::quit()");
m_quitFlag = true;
QuitRequest* m_quitRequest = new QuitRequest(*this);
m_requestQueue->enqueue(*m_quitRequest);
return(true);
}
int YourComponentNameComponentHandler::QuitRequest::call()
{
// Clean up memory
// Deactivate the component
m_handler->deactivate();
return(0);
}
Remove owner argument to the component handler constructor
In YourComponentNameComponentHandler.h, the code :
YourComponentNameComponentHandler(Adapter& owner);
is replace by :
YourComponentNameComponentHandler();
In YourComponentNameComponentHandler.cpp, the code :
YourComponentNameComponentHandler::YourComponentNameComponentHandler(Adapter& owner)
: ComponentHandlerQueueAbstract(owner),
is replace by :
YourComponentNameComponentHandler::YourComponentNameComponentHandler()
: ComponentHandlerQueueAbstract(),
MarieXMLDataFactory don't exist anymore
If you are using MarieXMLDataFactory in your component, you need to replace your code by the following :
// Includes to access the factory #include <DataFactory.h> #include <SerDesFactory.h>
// Get an instance of a XML factory
SerDesFactory& serdesFactory = SerDesFactory::getInstance();
DataFactory* factory = serdesFactory.createDataFactory("MARIEXML");
// Serialize and deserialize factory->serialize(yourMarieDataObject); factory->deserialize(yourXMLstring);
Simplify the visitor
In YourComponentNameVisitorConfig.cpp, replace the code segment
ACE_DLList<ConfigElementAbstract>& list = element.getElements();
ACE_DLList_Iterator<ConfigElementAbstract> iter(list);
while(!iter.done())
{
iter.next()->accept(*this);
iter++;
}
by :
visitComposite(element);
You need to replace that code segment for the following functions (if applicable) :
- bool YourComponentNameVisitorconfig::visit(ConfigElementQualifier& element);
- bool YourComponentNameVisitorconfig::visit(ConfigElementType& element);
- bool YourComponentNameVisitorconfig::visit(Configuration& element);
Configuration files modification
Because MARIE 0.5 is backward compatible with MARIE 0.4, there is no modification to be done to the configuration file.
Nevertheless, to take advantage of MARIE 0.5 new features, the configuration file need to be changed and use in a project file. See the explanation on how to build project with MARIE 0.5 here.
Scripts modification
Bash scripts are often use to lunch MARIE component, configure them and interact with them. A small modification is necessary to your existing scripts to use them with MARIE 0.5.
The original script section :
aaYourComponentName 12000 12001 appman -p 12001 -c sxml:./config.xml appman -p 12000 -c init appman -p 12000 -c start
Should be modified to :
aaYourComponentName 12000 12001 appman -p 12001 -c sxml:./config.xml appman -p 12000 -c init appman -p 12000 -c activateAllPorts // Need to manually activate the port appman -p 12000 -c start
Build system modification
Adapter should be linked with libmariecore instead of libmariecommon

