Versions Compared

Key

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

...

Code Block
languagecpp
themeDJango
linenumberstrue
collapsetrue
void calibrateSync() {
  // do calibration...
}

void ExampleImpl::calibrate() {
    new std::thread first(calibrateSync); //Thread resources are never de-allocated for simplicity
}

Queuing

A second approach based on design and programming language alone, is to populate queues with the actions that will be orchestrated by a separate thread.

Code Block
languagecpp
themeDJango
linenumberstrue
collapsetrue
void calibrateSync() {
    // do calibration...
}


//Function running on some other thread...
void run() {
    while (!stop) {
        if (queue.size() > 0) {
            if (queue.pop() == CALIBRATE_ACTION) {
                calibrateSync();
            } else {
                //Some error
            }
        }
    }
}
void ExampleImpl::calibrate() {
    queue.push(CALIBRATE_ACTION);
}

...

Oneway is a concept in CORBA that is defined as a keyword in the IDL interface methods, which makes sure the caller continues with the execution without waiting for anything from the client. This is similar to threading/queuing options, but is stronger, in the sense that it is not possible to receive a return value nor to raise an exception.

The IDL itself has the information about the asynchronous mechanism:

Code Block
languagecpp
themeDJango
linenumberstrue
collapsetrue
interface Example: ... {
    ...
    oneway void calibrate();
    ...
}

The actual implementation is very simple:

Code Block
languagecpp
themeDJango
linenumberstrue
collapsetrue
void ExampleImpl::calibrate() {
    // do calibration...
}

Reporting on Asynchronous Calls

Offshoots

Offshoots are the most basic form to report back to the caller. The base interface is actually empty:

Code Block
languagecpp
themeDJango
linenumberstrue
collapsetrue
interface OffShoot {};

This is by design, allowing anyone to extend such interface as they prefer. For instance:

Code Block
languagecpp
themeDJango
linenumberstrue
collapsetrue
module Definitions {
    interface SimpleCallback : ACS::OffShoot {
        oneway void report(in boolean error);
    };
};

Has a single method that can be called 'report', which has an 'in' parameter, stating whether there was an error. It could be used in the 'calibrate' example as follows:

Code Block
languagecpp
themeDJango
linenumberstrue
collapsetrue
interface Example: ... {
    ...
    oneway void calibrate(in Definitions::SimpleCallback cB);
    ...
}

Which would lead to an implementation (Assuming the oneway case) as follows:

Code Block
languagecpp
themeDJango
linenumberstrue
collapsetrue
void ExampleImpl::calibrate(SimpleCallback* cb) {
    // do calibration...
    cb->report(status);
}

The offshoot can be used with either of the 3 asynchronous mechanisms, and you will have to decide on one of them depending on your preferences and a trade-off limitations/requirements from each approach.

Callbacks

Callbacks are in fact a specialization of the Offshoot and are

BACI Actions