To implement startup and shutdown sequence, a recommended practice would be to implement a context class to hold the SCA instance (dca::DcaInstance) and other SCA objects. An instance of the context could then be passed to a startup function.
class MyDcaContext
{
public:
MyDcaContext() : inShutDown (false)
{ }
virtual ~MyDcaContext()
{
inShutDown = true;
updateModule.cancelUpdate();
}
virtual bool Init();
volatile bool inShutDown;
...
};
The startup function should first create the dca::DcaInstance object of the context class, and then the other SCA objects.
bool MyDcaContext::Init()
{
try
{
...
license = dcaInstance.createLicense( licenseData );
...
dbConnection = dcaInstance.createDbConnection ( connectData );
UrlDbClassifier = urlClassification.createUrlDbClassifier( dbConnection );
...
return true;
}
{
return false;
}
catch(...)
{
return false;
}
}
Call startup in the main() function in the identical scope:
{
try
{
...
MyDcaContext myContext;
myContext.Init();
DoWork( myContext );
return 0;
}
{
...
}
catch(...)
{
...
}
return 10;
}