Versions Compared

Key

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

...

  • Python

    Code Block
    languagepy
    linenumberstrue
    collapsetrue
    class <name>(...):
        ...
        def initialize():
            #Assign variable values
            #Initialize data
            ...
        def execute():
            #Retrieve components
            #Consider ready to receive calls (Change states if appropriate)
            ...
        def cleanUp():
            #Release components
            #Release resources
            ...
        def aboutToAbort():
            #Do any critical clean up
            #Continue with less critical stuff such as releasing components and other activities similar to cleanUp
            ...
        ...


  • Java

    Code Block
    languagejava
    linenumberstrue
    collapsetrue
    import alma.acs.container.ContainerServices;
    import alma.acs.component.ComponentLifecycleException;
    
    public class <name> ... {
        ...
        public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
            super.initialize(containerServices);
            //Assign variable values
            //Initialize data 
            ...
        }
    
        public void execute() {
            //Retrieve components
            //Consider ready to receive calls (Change states if appropriate)
            ...
        }
        public void cleanUp() {
            //Release components
            //Release resources
            ...
        }
        public void aboutToAbort() {
            //Do any critical clean up
            //Continue with less critical stuff such as releasing components and other activities similar to cleanUp
            ...
        }
        ...
    }


  • C++

    Code Block
    languagecpp
    linenumberstrue
    collapsetrue
    class <name> : ... {
        ...
        void initialize();
        void execute();
        void cleanUp();
        void aboutToAbort();
        ...
    };


    Code Block
    languagecpp
    linenumberstrue
    collapsetrue
    void <name>::initialize() {
        //Assign variable values
        //Initialize data
        ...
    }
    
    void <name>::execute() {
        //Retrieve components
        //Consider ready to receive calls (Change states if appropriate)
        ...
    }
    
    void <name>::cleanUp() {
        //Release components
        //Release resources
        ...
    }
    
    void <name>::aboutToAbort() {
        //Do any critical clean up
        //Continue with less critical stuff such as releasing components and other activities similar to cleanUp
        ...
    }


...

Example Logging

  • Python

    Code Block
    languagepy
    linenumberstrue
    collapsetrue
    logger = selflogger = self.getLogger()
    logger.logTrace("...")
    logger.logDebug("...")
    logger.logInfo("...")
    logger.logWarning("...")
    logger.logError("...")
    
    #An example
    logger.info("A real log with a string '%s' and an int (%d)" % ("Log Entry", 3))


  • Java

    Code Block
    languagejava
    linenumberstrue
    collapsetrue
    m_logger.finer("...");
    m_logger.fine("...");
    m_logger.info("...");
    m_logger.warning("...");
    m_logger.severe("...");
    
    
    #An example
    m_logger.info("A real log with a string '" + "Log Entry" + "' and an int (" + String.valueOf(3) + ")");


  • C++

    Code Block
    languagecpp
    linenumberstrue
    collapsetrue
    ACS_TRACE("...");
    ACS_DEBUG("...");
    ACS_SHORT_LOG((LM_INFO, "..."));
    ACS_SHORT_LOG((LM_WARNING, "..."));
    ACS_SHORT_LOG((LM_ERROR, "..."));
    
    
    //An example
    ACS_SHORT_LOG((LM_INFO, "A real log with a string '%s' and an int (%d)", "Log Entry", 3));


...

  • Error Definitions (XML)
  • Error Declarations (IDL)
  • Throwing Exceptions
  • Handling Exceptions

Error Definitions

Error

...

definitions are elements in XML files with the representation for errors and completions. For instance, a simple definition present in the project:

Code Block
languagexml
linenumberstrue
collapsetrue
...
<ErrorCode name="AlreadyInAutomatic" 
           shortDescription="Already in automatic mode" 
           description="Trying to set automatic mode, failed. It has already been set"/>
...

Error Declarations

The errors defined in the XML files need to be declared in the IDLs to be used in component communications:

Code Block
languagecpp
linenumberstrue
collapsetrue
...
    void setMode(in boolean mode) raises(SYSTEMErr::AlreadyInAutomaticEx);
...

Throwing Exceptions

Throwing exceptions is done in the servant that implements the IDL method that declared the error.

  • Python

    Code Block
    languagepy
    linenumberstrue
    collapsetrue
    import SYSTEMErrImpl
    ...
        raise SYSTEMErrImpl.AlreadyInAutomaticExImpl().getAlreadyInAutomaticEx()
    ...


  • Java

    Code Block
    languagejava
    linenumberstrue
    collapsetrue
    import alma.SYSTEMErr.wrappers.AcsJAlreadyInAutomaticEx;
    ...
        throw new AcsJAlreadyInAutomaticEx("Some message...").toAlreadyInAutomaticEx();
    ...


  • C++

    Code Block
    languagecpp
    linenumberstrue
    collapsetrue
    #include <SYSTEMErr.h>
    ...
        throw SYSTEMErr::AlreadyInAutomaticExImpl(__FILE__, __LINE__, "Some message...").getAlreadyInAutomaticEx();
    ...


Handling Exceptions

Handling is done in the component or client that calls a component through its stub.

  • Python

    Code Block
    languagepy
    linenumberstrue
    collapsetrue
    import SYSTEMErr
    ...
        try:
            ...
        except SYSTEMErr.AlreadyInAutomaticEx as e:
            ...
    ...


  • Java

    Code Block
    languagejava
    linenumberstrue
    collapsetrue
    import alma.SYSTEMErr.AlreadyInAutomaticEx;
    ...
        try {
            ...
        } catch (AlreadyInAutomaticEx e) {
            ...
        }
    ...


  • C++

    Code Block
    languagecpp
    linenumberstrue
    collapsetrue
    #include <SYSTEMErr.h>
    ...
        try {
            ...
        } catch(SYSTEMErr::AlreadyInAutomaticEx &_ex) {
            ...
        }
    ...


DataTypes Mapping

Python

Code Block
languagepy
titleImageType
linenumberstrue
collapsetrue
#Sending --- Img (list of int[0-255]) to string (OctetSeq mapping)
img = [2,3,12,...]
octseq = bytes(bytearray(img))

#Receiving --- OctetSeq mapping to Img (list of int[0-255])
octseq = takeImage(...)
b = bytearray()
b.extend(octseq)
img = list(b)


Code Block
languagepy
titleImageList
linenumberstrue
collapsetrue
#Sending
img = [2,3,12,...]
octseq = str(bytearray(img))
imgList = [octseq, octseq, octseq]


#Receiving
imgList = ...
imgs = []
for octseq in imgList
    b = bytearray()
    b.extend(octseq)
    img = list(b)
    imgs.append(img)


Code Block
languagepy
titlePosition
linenumberstrue
collapsetrue
from TYPES import Position


#Sending
pos = Position(az, el)


#Receiving
pos = ...
az = pos.az
el = pos.el


Code Block
languagepy
titleTarget
linenumberstrue
collapsetrue
from TYPES import Target
from TYPES import Position


#Sending
pos = Position(az, el)
tar = Target(tid, pos, expTime)


#Receiving
tar = ...
tid = tar.tid
pos = tar.pos
eTime = tar.expTime


Code Block
languagepy
titleTargetList
linenumberstrue
collapsetrue
from TYPES import Target
from TYPES import Position

#Sending
pos = Position(az, el)
tar = Target(tid, pos, expTime)
tList = [tar, tar, tar]

#Receiving
tarList = ...
for tar in tarList:
    tid = tar.tid
    pos = tar.pos
    eTime = tar.expTime
    ...


Code Block
languagepy
titleProposal
linenumberstrue
collapsetrue


Code Block
languagepy
titleProposalList
linenumberstrue
collapsetrue


Code Block
languagepy
titleRGB
linenumberstrue
collapsetrue

Java

Code Block
languagepy
titleImageType
linenumberstrue
collapsetrue
#Sending --- Img (list of int[0-255]) to string (OctetSeq mapping)
img = [2,3,12,...]
octseq = str(bytearray(img))

#Receiving --- OctetSeq mapping to Img (list of int[0-255])
octseq = takeImage(...)
b = bytearray()
b.extend(octseq)
img = list(b)


Code Block
languagepy
titleImageList
linenumberstrue
collapsetrue
#Sending
img = [2,3,12,...]
octseq = str(bytearray(img))
imgList = [octseq, octseq, octseq]


#Receiving
imgList = ...
imgs = []
for octseq in imgList
    b = bytearray()
    b.extend(octseq)
    img = list(b)
    imgs.append(img)


Code Block
languagepy
titlePosition
linenumberstrue
collapsetrue
from TYPES import Position


#Sending
pos = Position(az, el)


#Receiving
pos = ...
az = pos.az
el = pos.el


Code Block
languagepy
titleTarget
linenumberstrue
collapsetrue
from TYPES import Target
from TYPES import Position


#Sending
pos = Position(az, el)
tar = Target(tid, pos, expTime)


#Receiving
tar = ...
tid = tar.tid
pos = tar.pos
eTime = tar.expTime


Code Block
languagepy
titleTargetList
linenumberstrue
collapsetrue
from TYPES import Target
from TYPES import Position

#Sending
pos = Position(az, el)
tar = Target(tid, pos, expTime)
tList = [tar, tar, tar]

#Receiving
tarList = ...
for tar in tarList:
    tid = tar.tid
    pos = tar.pos
    eTime = tar.expTime
    ...


Code Block
languagepy
titleProposal
linenumberstrue
collapsetrue


Code Block
languagepy
titleProposalList
linenumberstrue
collapsetrue


Code Block
languagepy
titleRGB
linenumberstrue
collapsetrue

C++

Code Block
languagecpp
titleImageType
linenumberstrue
collapsetrue
#Send
ImageType img;
img.length(3);
img[0] = 10;
img[1] = 20;
img[2] = 30;


#Receive
ImageType_var img = ...
for(unsigned int i = 0; i < img->length(); i++) { //You should also be able to use iterators...
    ...(*img)[i]...
}


Code Block
languagepy
titleImageList
linenumberstrue
collapsetrue
#Send
ImageList imgList;
imgList(2);
ImageType img1;
...
imgList[0] = img1;
ImageType img2;
...
imgList[1] = img1;


#Receive
imgList_var = ...
for(unsigned int i = 0; i < imgList->length(); i++) { //You should also be able to use iterators...
    for(unsigned int j = 0; j < (*imgList)[i].length(); j++) { //You should also be able to use iterators...
        ...(*imgList)[i][j]...
}


Code Block
languagepy
titlePosition
linenumberstrue
collapsetrue


Code Block
languagepy
titleTarget
linenumberstrue
collapsetrue


Code Block
languagepy
titleTargetList
linenumberstrue
collapsetrue


Code Block
languagepy
titleProposal
linenumberstrue
collapsetrue


Code Block
languagepy
titleProposalList
linenumberstrue
collapsetrue


Code Block
languagepy
titleRGB
linenumberstrue
collapsetrue

Throwing Exceptions

...