Install component's IDL

In case you haven't done this step already, you must Build and install IDL first.

Create component

cd ~/workspace
getTemplateForDirectory MODROOT_WS cppHelloComp
cd cppHelloComp/src
touch HelloComponentImpl.cpp
touch ../include/HelloComponentImpl.h
vim Makefile

We modify the Makefile for this component:

cppHelloComp/src/Makefile
...
INCLUDES = HelloComponentImpl.h
...
LIBRARIES = HelloComponentImpl
HelloComponentImpl_OBJECTS = HelloComponentImpl
HelloComponentImpl_LIBS = HelloComponentStubs acscomponent
...

We fill the component code as follows:

vim ../include/HelloComponentImpl.h
cppHelloComp/include/HelloComponentImpl.h
#ifndef _HELLO_COMPONENT_IMPL_H
#define _HELLO_COMPONENT_IMPL_H
 
#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif
 
//Base component implementation, including container services and component lifecycle infrastructure
#include <acscomponentImpl.h>
 
//Skeleton interface for server implementation
#include <HelloComponentS.h>
 
//Error definitions for catching and raising exceptions
class HelloComponentImpl : public virtual acscomponent::ACSComponentImpl, public virtual POA_workshop::HelloComponent {
  public:
    HelloComponentImpl(const ACE_CString& name, maci::ContainerServices * containerServices);
    virtual ~HelloComponentImpl();
    char* printHello();
};
 
#endif
vim HelloComponentImpl.cpp
cppHelloComp/src/HelloComponentImpl.cpp
#include <HelloComponentImpl.h>
 
HelloComponentImpl::HelloComponentImpl(const ACE_CString& name, maci::ContainerServices * containerServices) : ACSComponentImpl(name, containerServices) {
}
 
HelloComponentImpl::~HelloComponentImpl() {
}
 
char* HelloComponentImpl::printHello() {
    std::cout << "Just printing 'Hello World!'" << std::endl;
    return CORBA::string_dup("Hello World!");
}
 
/* --------------- [ MACI DLL support functions ] -----------------*/
#include <maciACSComponentDefines.h>
MACI_DLL_SUPPORT_FUNCTIONS(HelloComponentImpl)
/* ----------------------------------------------------------------*/

Compile component

make all install

Add component to CDB

vim $ACS_CDB/CDB/MACI/Components/Components.xml

Add the following item:

Components.xml
<e Name="HelloWorldCPP"
   Code="HelloComponentImpl"
   Type="IDL:acsws/workshop/HelloComponent:1.0"
   Container="bilboContainer" ImplLang="cpp" />

Testing

Create client python file:

cd ~/workspace
touch client.py
vim client.py

We fill it as follow:

~/workspace/client.py
from Acspy.Clients.SimpleClient import PySimpleClient
 
client = PySimpleClient()
component = client.getComponent("HelloWorldCPP")

print(component.printHello())

Run component:

# in one terminal
acsStop
acsStart
# in a different terminal
acsStartContainer -cpp bilboContainer
# in a different terminal
python client.py

Example output:

...
Hello World!
...
  • No labels