Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Makefile

The Makefile is provided with the module generated from getTemplateForDirectory. In the case of C++ server implementation, you need to configure the compilation and installation of a C++ library (Shared Object) file:

Code Block
titleMakefile for Java
LIBRARIES:=<LibraryName>
<LibraryName>_OBJECTS = <ListOfObjectsToInclude> #.c and/or .cpp files
<LibraryName>_LIBS = <ListOfLibraryDependencies> #<Interface>Stubs acscomponent ServiceErr <Interface>Err #etc.

Implementation

The first thing needed to implement a server, is to

...

add the required

...

include files:

Code Block
languagejavacpp
titleJava ImportsC++ Imports
#ifndef _<FILENAME>_H
#define _<FILENAME>_H

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif//Suggested: import alma.<Module>.<Interface>Impl; //But anything, really
package <ChosenPackage>;

//Base component implementation, including container services and component lifecycle infrastructure
import#include alma.acs.component.ComponentImplBase;<acscomponentImpl.h>


//Skeleton interface for server implementation
import#include alma.<Module>.<Interface>Operations;<<Interface>S.h>


//Error definitions for catching and raising exceptions
import#include alma.ServiceErr.<ExceptionName>Ex;
import alma.<Interface>Err.<ExceptionName>Ex;

//Error definitions for raising exceptions
import alma.ServiceErr.wrappers.AcsJ<ExceptionName>Ex;
import alma.<Interface>Err.wrappers.AcsJ<ExceptionName>Ex;<ServiceErr.h>
#include <<Interface>Err.h>

...


#endif

Besides this, there's the need to create the class using the mentioned infrastructure provided by the imported class and interface:

Code Block
languagejavacpp
titleJava Server Class Definition
//ClassName usually is <Interface> or <Interface>Impl, but can be anything
public class <ClassName>: extendspublic ComponentImplBase implements <Interface>Operations {

In the case of Java, there's a helper class. Luckily for us, a template for this class is generated from the IDLs and can be found in $REPO_PATH/ICD/src/alma/<Module>/<Interface>Impl/<Interface>ComponentHelper.java.tpl after compiling the module. This template has to be copied to your own module and in whatever package you chouse (although is recommended to use the same that was generated). If this is respected, and the package and class naming conventions for your own implementation respected the suggested values, then there's no change needed in the file (besides removing the .tpl extension). In case you decided to use your own conventions look for these parts of the template and edit them accordingly:

Code Block
languagejava
titleJava Server Class Definition
//Replace package alma.<Module>.<Interface>Impl; //for:
package alma.<PackageChosenForComponentHelper>;

//Replace import alma.Observatory.SchedulingImpl.SchedulingImpl; //for:
import alma.<PackageChosenForComponentImpl>.<ClassNameForComponentImpl>;

//Replace return new SchedulingImpl(); // for
return new <ClassNameForComponentImpl>()virtual acscomponent::ACSComponentImpl, public POA_<Module>::<Interface>
{
  public:
    <Interface>(const ACE_CString& name, maci::ContainerServices * containerServices);
    ...
};

To access a struct, enum, typedef or definition in a module or in an interface, simply do the following:

Code Block
languagejavacpp
titleJava C++ Types Usage
//From IDL <Module>::<EnumName>::<VALUE>
import alma.<Module>.<EnumName>;
<EnumName>.<Module>::<VALUE>;

#From IDL <Module>::<Interface>::<Enumname>::<VALUE>
import alma.<Module>.<Interface>Package.<EnumName>;
<EnumName>.<Module>::<Interface>::<VALUE>;

To retrieve a component to interact with, simply do the following:

Code Block
languagejavacpp
titleJava C++ Component Interaction
//Shared
import alma.<Module>.<Interface>;
import alma.<Module>.<Interface>Helper;

//By Name
<Module>::<Interface>_var comp = <Interface>Helper.narrow(this.m_containerServices.getComponentthis->getContainerServices()->getComponent<<Module>::<Interface>>("<Name>"));

//By Interface. Must be at least one component configured as default!
<Module>::<Interface>_var comp = <Interface>Helper.narrow(this.m_containerServices.getDefaultComponentthis->getContainerServices()->getDefaultComponent<<Module>::<Interface>>("IDL:alma/<Module>/<Interface>:1.0"));

//Release Components
m_containerServies.releaseComponent(comp.namethis->getContainerServices()->releaseComponent(comp->name());

For logging , as you saw in the class constructor, there's a facility provided by the component. To use it, simply do as followsin C++, there are some macros to help:

Code Block
languagejavacpp
titleJava C++ Logger
mACS_logger.finerTRACE("...");
mACS_logger.fineDEBUG("...");
m_logger.info(ACS_SHORT_LOG((LM_INFO, "..."));
m_logger.warning(ACS_SHORT_LOG((LM_WARNING, "..."));
m_logger.severe(ACS_SHORT_LOG((LM_ERROR, "..."));

For catching and raising exceptions:

Code Block
languagejavacpp
titleJava C++ Error Handling
//Shared
#include <<Interface>Err.h>

//For catching exceptions
import alma.<Interface>Err.<ExceptionName>Ex;
catch (<ExceptionName>Ex e) {//Along CORBA calls
catch(<Interface>Err::<ExceptionName>Ex &_ex) { ... }
//Internally in the server... more convenient to edit parameters or log if needed
catch(<Interface>Err::<ExceptionName>ExImpl &_ex) { ... }

//For raising exceptions
import alma.<Interface>Err.wrappers.AcsJ<ExceptionName>Ex;
throw new AcsJ<ExceptionName>Ex("<CustomMessage>").to<ExceptionName>Ex()
//Along CORBA calls
throw <Interface>Err::<ExceptionName>ExImpl(__FILE__, __LINE__, "<CustomMessage>").get<ExceptionName>Ex();
//Internally in the server...
throw <Interface>Err::<ExceptionNanem>ExImpl(__FILE__, __LINE__, "<CustomMessage>");

//For raising exceptions with parameters
import alma.<Interface>Err.wrappers.AcsJ<ExceptionName>Ex;
AcsJ<ExceptionName>Ex err = new AcsJ<ExceptionName>Ex(<Interface>Err::<ExceptionName>ExImpl err(__FILE__, __LINE__, "<CustomMessage>");
err.set<ParamName>(<Value>);
raisethrow err.to<ExceptionName>Exget<ExceptionName>Ex();

//For logging an error message from the exceptions
import alma.<Interface>Err.wrappers.AcsJ<ExceptionName>Ex;
AcsJ<ExceptionName>Ex err = <Interface>ErrImpl.<ExceptionName>ExImpl()<Interface>Err::<ExceptionName>ExImpl err(__FILE__, __LINE__, "<CustomMessage>");
err.log(m_logger);
raisethrow err.to<ExceptionName>Exget<ExceptionName>Ex();