docs:rtlib:newapp

Creating a new integrated application

Basic command:

$ bbque-layapp

Generated files

Main

#include <bbque/simple_exc.h>
 
int main(...) {
	...
 
	RTLIB_Services_t * rtlib;
	RTLIB_Init("SimpleApp", &rtlib);
 
	if (!rtlib) {
		logger->Error("Error during initialization");
		return -1;
	}
 
	std::shared_ptr<SimpleEXC> myExeC = std::make_shared<SimpleApp>("SimpleApp", recipe_name, rtlib);
	if (!myExeC) 
		logger->Error("Execution Context registration failed");
		return -2;
	}
 
	result = myExeC->Start();
	if (result != RTLIB_OK) {
		logger->Error("Unable to start the Execution Context");
		return -3;
	}
 
        // Wait for the termination condition
        myExeC->WaitCompletion();
 
	return EXIT_SUCCESS;
}

In order to communicate with the Barbeque RTRM, the first step required to the applications is the initialization of the communication channel, and the retrieving of the services provided by the framework. This step is performed by the RTLIB_Init() call. The RTLIB_Services_t structure returned by the BarbequeRTRM contains a reference to all the services that the application can require. For further details, please check bosp/out/include/bbque/rtlib.h. A NULL return is a fatal error condition, meaning that the initialization has gone wrong and thus that the application cannot communicate with the framework.

Once the communication with the resource manager has been setup, we can instantiate our Execution Context. This is done by instantiating the SimpleEXC class. The arguments of the constructor will feature three values:

  • The name associated to the application/EXC
  • The name of the recipe file (excluding “.recipe” extension)
  • The reference to the RTLIB_Service_t returned by the previous call.

If the class has been correctly instanced then the registration is successfully performed.

At this point, we are ready to require the execution of our simple EXC, by invoking the member function Start(). This will start the Execution Context control thread. All we have to do in the main is to wait for its completion (WaitCompletion()).

BbqueEXC derived class

Once, from the main, a call to the member function Start() has been performed, an Execution Context control thread starts, running a managed loop. Inside this loop, a set of SimpleApp member function callbacks can be invoked, accordingly to the the resource management actions of the BarbequeRTRM.

The stub code of the BbqueEXC derived class, implementing the Abstract Execution Model of our application, is located in files src/*_exc.cc and include/*_exc.h.

/** FILE simple_app_exc.h **/
 
#include <bbque/bbque_exc.h>
 
class SimpleApp : public BbqueEXC {
 
public:
        // SimpleApp constructor code
	SimpleApp(std::string const & name,
		  std::string const & recipe,
		  RTLIB_Services_t *rtlib):
	    // Call the super class constructor!
	    BbqueEXC(name, recipe, rtlib) {
	}
 
        // Destructor
	virtual ~SimpleApp() { }
 
private:
	// (Mandatory) member functions to be implemented
	RTLIB_ExitCode_t onSetup();
	RTLIB_ExitCode_t onConfigure(uint8_t awm_id);
	RTLIB_ExitCode_t onRun();
	RTLIB_ExitCode_t onMonitor();
 
	// (Optional) member functions to be implemented
	RTLIB_ExitCode_t onSuspend();
	RTLIB_ExitCode_t onRelease();
};

The class must be implemented according to the guidelines provided in RTLib Abstract Execution Model (AEM) API, whom we described in the first tutorial. Before dealing in detail on how to create a recipe, please follow that last basic tutorial.

docs/rtlib/newapp.txt · Last modified: 2017/05/16 22:50 by jumanix

Page Tools