...
First we create the directory for the IDL:
Code Block |
---|
|
> getTemplateForDirectory MODROOT_WS idlHelloComp
> cd idlHelloComp/src
> touch ../idl/HelloComponent.idl |
...
We then compile and install the IDL definitions:
Code Block |
---|
language | bash |
---|
title | Compilation |
---|
|
make -j> make all install |
Configuration
The following image depicts the deployment configuration needed:
...
Add the following configuration in the $ACS_CDB/CDB/MACI/Components/Components.xml:
...
Implementation
Python
Code Block |
---|
language | bash |
---|
title | pyHelloComp |
---|
|
> getTemplateForDirectory MODROOT_WS pyHelloComp
> cd pyHelloComp/src
> mkdir ws
> touch ws/__init__.py
> touch ws/HelloComponentImpl.py |
We modify the Makefile for this component:
Code Block |
---|
title | pyHelloComponentpyHelloComp/src/Makefile |
---|
|
...
PY_PACKAGES = ws
... |
...
Code Block |
---|
language | py |
---|
title | pyHelloComponentpyHelloComp/src/workshopws/HelloComponentImpl.py |
---|
linenumbers | true |
---|
collapse | true |
---|
|
#Client# Client stubs and definitions, such as structs, enums, etc.
import workshop
#Skeleton# Skeleton infrastructure for server implementation
import workshop__POA
#Base# Base component implementation
from Acspy.Servants.ACSComponent import ACSComponent
#Services# Services provided by the container to the component
from Acspy.Servants.ContainerServices import ContainerServices
#Basic# Basic component lifecycle (initialize, execute, cleanUp and aboutToAbort methods)
from Acspy.Servants.ComponentLifecycle import ComponentLifecycle
class HelloComponentImpl(workshop__POA.HelloComponent, ACSComponent, ContainerServices, ComponentLifecycle):
def __init__(self):
ACSComponent.__init__(self)
ContainerServices.__init__(self)
self._logger = self.getLogger()
def printHello(self):
print("Just printing 'Hello World!'")
return "Hello World!" |
Java
Code Block |
---|
language | bash |
---|
title | jHelloComp |
---|
|
> getTemplateForDirectory MODROOT_WS jHelloComp
> cd jHelloComp/src
> mkdir -p acsws/workshop/HelloComponentImpl
> touch acsws/workshop/HelloComponentImpl/HelloComponentImpl.java
> cp ../../idlHelloComp/src/acsws/workshop/HelloComponentImpl/HelloComponentComponentHelper.java.tpl acsws/workshop/HelloComponentImpl/HelloComponentComponentHelper.java |
We modify the Makefile for this component:
Code Block |
---|
title | jHelloComponentjHelloComp/src/Makefile |
---|
|
...
JARFILES = HelloComponentImpl
HelloComponentImpl_DIRS = acsws
... |
...
Code Block |
---|
language | java |
---|
title | jHelloComponentjHelloComp/src/acsws/workshop/HelloComponentImpl/HelloComponentImpl.java |
---|
linenumbers | true |
---|
collapse | true |
---|
|
//Suggested: import alma.<Module>.<Interface>Impl; //But anything, really
package acsws.workshop.HelloComponentImpl;
//Base component implementation, including container services and component lifecycle infrastructure
import alma.acs.component.ComponentImplBase;
//Skeleton interface for server implementation
import acsws.workshop.HelloComponentOperations;
//ClassName usually is <Interface>Impl, but can be anything
public class HelloComponentImpl extends ComponentImplBase implements HelloComponentOperations {
public HelloComponentImpl() {
}
public String printHello() {
System.out.println("Just printing 'Hello World!'");
return new String("Hello World!");
}
} |
...
We create the needed directories:
Code Block |
---|
language | bash |
---|
title | cppHelloComp |
---|
|
> getTemplateForDirectory MODROOT_WS cppHelloComp
> cd cppHelloComp/src
> touch HelloComponentImpl.cpp
> touch ../include/HelloComponentImpl.h |
We modify the Makefile for this component:
Code Block |
---|
title | cppHelloComponentcppHelloComp/src/Makefile |
---|
|
...
INCLUDES = HelloComponentImpl.h
...
LIBRARIES = HelloComponentImpl
HelloComponentImpl_OBJECTS = HelloComponentImpl
HelloComponentImpl_LIBS = HelloComponentStubs acscomponent
... |
...
Code Block |
---|
language | cpp |
---|
title | cppHelloComponentcppHelloComp/include/HelloComponentImpl.h |
---|
linenumbers | true |
---|
collapse | true |
---|
|
#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 |
Code Block |
---|
language | cpp |
---|
title | cppHelloComponentcppHelloComp/src/HelloComponentImpl.cpp |
---|
linenumbers | true |
---|
collapse | true |
---|
|
#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)
/* ----------------------------------------------------------------*/ |
...
First launch your acs container with the good modified ACS _CDB (If you want to component to start with the container).CDB
Code Block |
---|
language | bash |
---|
title | Start container |
---|
|
acsStartContainer -py aragornContainer
acsStartContainer -java frodoContainer
acsStartContainer -cpp bilboContainer |
For simplicity, we implement a simple client in Python to communicate with the 3 programming languages:
Code Block |
---|
language | py |
---|
linenumbers | true |
---|
collapse | true |
---|
|
from Acspy.Clients.SimpleClient import PySimpleClient
client = PySimpleClient()
hc_py = client.getComponent("PY_HELLO_COMP")
print(hc_java = client.getComponent("JAVA_HELLO_COMP")py.printHello())
hc_cppjava = client.getComponent("CPPJAVA_HELLO_COMP")
print(hc_pyjava.printHello())
print(
hc_java.printHello())cpp = client.getComponent("CPP_HELLO_COMP")
print(hc_cpp.printHello())
|
Output
The output is seen on each container:
...