Versions Compared

Key

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

...

  • CBvoid
  • CBdouble(Seq)
  • CBfloat(Seq)
  • CBstring(Seq)
  • CBlong(Seq)
  • CBuLong(Seq)
  • CBboolean(Seq)
  • CBlongLong
  • CBuLongLong

Presentation

  • Scope
    • Simple oneway calls
    • Offshoot/Callback Architecture
  • Duration: 10 minutes

Hands-On Exercise

Component IDL

Code Block
languagecpp
titleAsync.idl
linenumberstrue
collapsetrue
#ifndef _ASYNC_IDL_
#define _ASYNC_IDL_

#pragma prefix "alma"

#include <acscommon.idl>
#include <acscomponent.idl>

module workshop
{
    interface Async : ACS::ACSComponent {
        oneway void delayResult(in ACS::uLong delay, in ACS::CBuLong cb, in ACS::CBDescIn desc);
    };
};
#endif

...

Code Block
languagecpp
titleAsyncImpl.h
linenumberstrue
collapsetrue
#ifndef _ASYNC_IMPL_H
#define _ASYNC_IMPL_H

#include <acscomponentImpl.h>
#include <AsyncS.h>

class AsyncImpl : public virtual acscomponent::ACSComponentImpl, public virtual POA_workshop::Async
{
  public:
    AsyncImpl(const ACE_CString& name, maci::ContainerServices* containerServices);
    virtual ~AsyncImpl();
    void delayResult(ACS::uLong delay, ACS::CBuLong_ptr cb, const ACS::CBDescIn& desc);
};
#endif
Code Block
languagecpp
titleAsyncImpl.cpp
linenumberstrue
collapsetrue
#include <AsyncImpl.h>
#include <ACSErrTypeOK.h>

AsyncImpl::AsyncImpl(const ACE_CString& name, maci::ContainerServices* containerServices) : acscomponent::ACSComponentImpl(name, containerServices) {
}

AsyncImpl::~AsyncImpl() {
}

void AsyncImpl::delayResult(ACS::uLong delay, ACS::CBuLong_ptr cb, const ACS::CBDescIn& desc) {
    ACSErr::Completion completion;
    ACS::CBDescOut descOut;

    completion = ACSErrTypeOK::ACSErrOKCompletion();
    cb->working(0, completion, descOut);
    sleep(delay);
    cb->done(delay, completion, descOut);
}

/* --------------- [ MACI DLL support functions ] -----------------*/
#include <maciACSComponentDefines.h>
MACI_DLL_SUPPORT_FUNCTIONS(AsyncImpl)
/* ----------------------------------------------------------------*/

...

Code Block
titleComponents.xml
linenumberstrue
collapsetrue
<e Name="ASYNC"
   Code="asyncImplAsyncImpl"
   Type="IDL:alma/workshop/Async:1.0"
   Container="bilboContainer"
   ImplLang="cpp"
   KeepAliveTime="0"
/>

...

Code Block
languagepy
titleAsyncClient.py
linenumberstrue
collapsetrue
import ACS
import time

from Acspy.Common.Callbacks import CBuLongCBuLongLong
from Acspy.Clients.SimpleClient import PySimpleClient

client = PySimpleClient()
comp = client.getComponent('ASYNC')

cb = CBuLongCBuLongLong()
cbObj = client.activateOffShoot(cb)
desc = ACS.CBDescIn(0, 0, 0)

print(cb.status)
comp.delayResult(8, cbObj, desc)

print(cb.status)
time.sleep(5)
print(cb.status)
time.sleep(5)
print(cb.status)

print(cb.values)

client.releaseComponent(comp.name)
client.disconnect()

...

Code Block
titleMakefile
linenumberstrue
collapsetrue
EXECUTABLES_L   = AsyncExample
AsyncExample_OBJECTS#Component IDL
IDL_FILES_L = AsyncClientAsync
AsyncExampleAsyncStubs_LIBS = maciClientacscomponentStubs AsyncStubsacscommonStubs

#C++ Component
LIBRARIES_L     = AsyncImpl
AsyncImpl_LIBSOBJECTS = AsyncStubs acscomponent

IDL_FILESAsyncImpl
AsyncImpl_LIBS = AsyncStubs acscomponent

#C++ Client
EXECUTABLES_L   = AsyncExample
AsyncExample_OBJECTS = Async
AsyncStubs_LIBS = acscomponentStubs acscommonStubsAsyncClient
AsyncExample_LIBS = maciClient AsyncStubs

#Java Client
JARFILES_L = AsyncJar
AsyncJar_DIRS = workshop

#Python Client
PY_SCRIPTS_L       = AsyncClient


Discussion

  • Asynchronous calls and oneway operations
    • It's not mandatory to make use of oneway keyword, depends on the design
      • For instance, adding to a queue may return immediately with a boolean with success or failure status of adding the element to a queue and may still register a callback for when the element is executed and something needs to be done
  • Existing CBxxxx are used for monitoring, alarms and other internals of ACS, they're not meant for generic use. Your own callbacks can have the desired set of methods
  • Improvements / Suggestions