dca_interface  6.3.4
Startup/Shutdown sequence

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()
{
// signal DCA worker threads to shutdown
inShutDown = true;
// this cancels the download or update task if it is currently running
updateModule.cancelUpdate();
// this cancels all long-lasting functions and forces them to return immediately
// such as database merge processes...
dcaInstance.signal( DCA_SIG_ABORT );
// ...
// wait for worker threads to finish
// ...
// all other DCA objects are destructed in reverse construction order
}
// initialize the DCA objects
virtual bool Init();
// Construction order is important!
// the DCA instance must always be created first.
dca::DcaInstance dcaInstance;
dca::InitData initData;
dca::License license;
dca::UpdateModule updateModule;
dca::DbConnectionData connectData;
dca::DbConnection dbConnection;
dca::UrlClassification urlClassification;
dca::UrlDbClassifier urlDbClassifier;
volatile bool inShutDown;
...
};

The startup function should first create the dca::DcaInstance object of the context class, and then the other SCA objects.

// creates all instances in a meaningful order
bool MyDcaContext::Init()
{
try
{
...
dcaInstance = dca::DcaInstance::create( initData );
license = dcaInstance.createLicense( licenseData );
...
dbConnection = dcaInstance.createDbConnection ( connectData );
urlClassification = dca::UrlClassification::create( license );
UrlDbClassifier = urlClassification.createUrlDbClassifier( dbConnection );
...
return true;
}
catch( const dca::ExDca& ex )
{
return false;
}
catch(...)
{
return false;
}
}

Call startup in the main() function in the identical scope:

int main()
{
try
{
...
MyDcaContext myContext;
// start up
myContext.Init();
// run application
DoWork( myContext );
// MyContext automatically shutdown
// The DCA instances will be destroyed in the
// reverse order of construction.
return 0;
}
catch( const dca::ExDca& ex )
{
...
}
catch(...)
{
...
}
// error occurred
return 10;
}
Exception class used in the DCA.
Definition: base_classes.h:237
The update module is used to download and install DCA content and engine updates.
Definition: base_classes.h:917
const unsigned int DCA_SIG_ABORT
Currently the only supported signal parameter for the DcaInstance::signal() function.
Stores the connection data for a database.
Definition: base_classes.h:815
Database connection class for a local or remote database.
Definition: base_classes.h:859
Main class for the URL classification.
URL database classifier class.
Use a License to initialize a classification package or a toolbox package.
Definition: base_classes.h:560
Encapsulates the init and deinit of the DCA API.
Definition: base_classes.h:315
static UrlClassification create(const DcaInstance &aDcaInstance, const License &aLicense)
Creates the URL classification module by using the given DcaInstance and License.
This structure is used to initialize the DcaInstance.
Definition: base_classes.h:264
static DcaInstance create(const InitData &initData)
Creates a DcaInstance, starts up the DCA API and initializes the required main module.
int main(int argc, char *argv[])
The main routine.