Introduction

On this day we will focus on implementing the logic for our component. By the end of the day, we expect the groups to:

Guides

As a guide, we're going to show you sample code for logging, to define exceptions, throw and catch exceptions.

Component Details

The component details will be presented in the first session from ACS Workshop - Project Details page to describe the interfaces and interactions of the project's components.

Lifecycle Methods

The ACS components have a couple of methods associated with its lifecycle that automatically gets executed at different phases of the component initialization and deactivation.

Implementing Lifecycle functionality

Retrieving and Releasing Components

During component interaction it will be needed to request and release components. When interacting with components from other components, you need to obtain the container services references to make the request to the Manager. Here we will show how to retrieve two types of components:

Example Request and Release

Logging

ACS Logging has two main benefits:

Example Logging

Error Handling

Error Handling in ACS Components has 4 pieces:

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:

...
<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:

...
    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.

Handling Exceptions

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

DataTypes Mapping

Python

#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)


#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)


from TYPES import Position


#Sending
pos = Position(az, el)


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


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


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
    ...




Java

#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)


#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)


from TYPES import Position


#Sending
pos = Position(az, el)


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


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


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
    ...




C++

#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]...
}


#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]...
}