Versions Compared

Key

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

...

Code Block
languagecpp
titleAsyncClient.cpp
linenumberstrue
collapsetrue
#include <maciSimpleClient.h>
#include <AsyncC.h>
#include <ACSErrTypeCommon.h>
#include <acsutilTimeStamp.h>
 
using namespace maci;
class CBuLongImpl : public virtual POA_ACS::CBuLong {
  public:
    CBuLongImpl() {value = 0; status=std::string("INIT");}
    virtual ~CBuLongImpl() {}
    void working (ACS::uLong value, const ACSErr::Completion &c, const ACS::CBDescOut &desc) {
        status = std::string("WORKING");
        this->value = value;
    }
    void done (ACS::uLong value, const ACSErr::Completion &c, const ACS::CBDescOut &desc){
        status = std::string("DONE");
        this->value = value;
    }
    CORBA::Boolean negotiate (ACS::TimeInterval time_to_transmit, const ACS::CBDescOut &desc) {
            return true;
    }
  public:
    ACS::uLong value;
    std::string status;
};
 
int main(int argc, char *argv[]) {
    SimpleClient client;
    workshop::Async_var comp;
 
    if (client.init(argc,argv) == 0) {
        return -1;
    } else {
        client.login();
    }
 
    try {
        comp = client.getComponent<workshop::Async>("ASYNC", 0, true);
    } catch(maciErrType::CannotGetComponentExImpl& _ex) {
        _ex.log();
        return -1;
    }
 
    CBuLongImpl cb{};
    ACS::CBuLong_var cbObj = cb._this();
    ACS::CBDescIn desc;
    desc.id_tag = 2;
 
    ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    comp->delayResult(8, cbObj.in(), desc);
 
    ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    sleep(5);
    ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    sleep(5);
 
    ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    ACS_SHORT_LOG((LM_INFO, "%ul", cb.value));
 
    try {
        client.releaseComponent("ASYNC");
    } catch(maciErrType::CannotReleaseComponentExImpl &_ex) {
        _ex.log();
        return -1;
    }
 
    client.logout();
 
    ACE_OS::sleep(3);
    return 0;
}

Makefile

Code Block
titleMakefile
linenumberstrue
collapsetrue
EXECUTABLES_L   = AsyncExample
AsyncExample_OBJECTS = AsyncClient
AsyncExample_LIBS = maciClient AsyncStubs


LIBRARIES_L     = AsyncImpl
AsyncImpl_LIBS = AsyncStubs acscomponent

IDL_FILES = Async
AsyncStubs_LIBS = acscomponentStubs acscommonStubs


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