customdb_samples: customdbsample


Introduction

This Custom Database sample demonstrates how to:

Syntax:

customdbsample <dca-redist-folder> <ticket> <product> 
        <custom-db-folder> <categories-folder>
custom-db-folder
The folder where the newly created database file will be saved in.
categories-folder
The folder where the custom categories XML files are stored in.
See also:
dca::UrlCustomDbModule
Custom Categories
customdb_samples: customdbsample_extended
customdb_samples: createdbsample
Package: Custom Database Module Toolbox
Samples Main Documentation: Samples

Files

file  customdb_samples/customdbsample/main.cpp
 

Custom Database sample program.


Defines

#define DCA_BINDIR   "bin/linux"
 DCA subdirectory of the DCA binaries.
#define DCA_INITDIR   "init"
 DCA subdirectory of the DCA initialization data.
#define DCA_LOGDIR   "./logs"
 Relative directory for logfile(s).

Functions

static void SetupInitData (const std::string &redist_folder, InitData &initData)
 Sets up the given initData by substituting the given redist_folder with DCA subdirectories.
static void SetupLicense (const std::string &ticket, const std::string &product, LicenseData &licenseData)
 Sets up the given licenseData by copying the given ticket and product strings.
static void SetupConnectionData (const std::string &custom_db_folder, DbConnectionData &cData)
 Sets up the given cData to use a custom URL database.
static void PrintToolHeader ()
 Prints out the name and the version of this sample.
static void PrintUsage (const char *name)
 Prints out the syntax of the sample.
static void PrintLicenseInfo (const License &aLicense)
 Prints out the information about the provided License.
static void PrintCategoriesInfo (const CategoriesInfo &myCategoriesInfo)
 Prints out the contents of the given myCategoriesInfo.
static void PrintUrlResult (const std::string &myUrlString, const std::set< int > &myCatSet)
 Simple routine that prints out all found categories for the given URL string.
void InitializeCustomDatabase (const DcaInstance &aDca, const License &aLicense, UrlCustomDb &myUrlCustomDb)
 Initialize all classes that are used to create the UrlCustomDb instance, and return the initialized myUrlCustomDb to the caller.
int ProcessCustomDatabase (const DcaInstance &aDca, const License &aLicense)
 First calls InitializeCustomDatabase() with given parameters and then takes the following steps:

  • add an URL with categorizations to the custom database
  • retrieve the categories for that URL and print them out
  • removs the URL from the custom database
  • retry to retrieve the previously removed URL.

int main (int argc, char *argv[])
 The main routine.

Variables

const std::string S_UsageString
 Usage string, displayed if a parameter is missing.

Function Documentation

static void SetupInitData ( const std::string &  redist_folder,
InitData initData 
) [static]

Sets up the given initData by substituting the given redist_folder with DCA subdirectories.

Parameters:
[in] redist_folder This is the folder where the DCA has been installed to (assuming trailing fileslash)
[out] initData The InitData structure to set up
Note:
Only DCA_BINDIR differs between Windows and Linux
The directory ./logs will be used for the logfile(s)

Definition at line 105 of file customdb_samples/customdbsample/main.cpp.

static void SetupLicense ( const std::string &  ticket,
const std::string &  product,
LicenseData licenseData 
) [static]

Sets up the given licenseData by copying the given ticket and product strings.

Parameters:
[in] ticket This is the ticket data as provided with your DCA license
[in] product This is the product shortcut e.g. DC oder MS etc
[out] licenseData The LicenseData structure to set up

Definition at line 120 of file customdb_samples/customdbsample/main.cpp.

static void SetupConnectionData ( const std::string &  custom_db_folder,
DbConnectionData cData 
) [static]

Sets up the given cData to use a custom URL database.

Parameters:
[in] custom_db_folder The folder where the Custom Database is located
[out] cData The DbConnectionData structure to set up
Note:
In the main() routine we first ensure that a database exists in the given custom_db_folder. If not, an empty database will be created.

Definition at line 135 of file customdb_samples/customdbsample/main.cpp.

static void PrintUsage ( const char *  name  )  [static]

Prints out the syntax of the sample.

Parameters:
[in] name The name of the executable

Definition at line 158 of file customdb_samples/customdbsample/main.cpp.

static void PrintLicenseInfo ( const License aLicense  )  [static]

Prints out the information about the provided License.

Parameters:
[in] aLicense The license for which information should be displayed

Definition at line 170 of file customdb_samples/customdbsample/main.cpp.

static void PrintCategoriesInfo ( const CategoriesInfo myCategoriesInfo  )  [static]

Prints out the contents of the given myCategoriesInfo.

Parameters:
[in] myCategoriesInfo The CategoriesInfo previously created by a call to UrlCustomDbModule::createCategories()

Definition at line 198 of file customdb_samples/customdbsample/main.cpp.

static void PrintUrlResult ( const std::string &  myUrlString,
const std::set< int > &  myCatSet 
) [static]

Simple routine that prints out all found categories for the given URL string.

Parameters:
[in] myUrlString The URL string used for the database request
[in] myCatSet The cageories returned from the getUrl() call

Definition at line 254 of file customdb_samples/customdbsample/main.cpp.

void InitializeCustomDatabase ( const DcaInstance aDca,
const License aLicense,
UrlCustomDb myUrlCustomDb 
)

Initialize all classes that are used to create the UrlCustomDb instance, and return the initialized myUrlCustomDb to the caller.

If any function fails, an exception of type ExDca will be thrown

InitializeCustomDatabase is called from ProcessCustomDatabase()

Parameters:
[in] aDca An already initialized DcaInstance object
[in] aLicense An already initialized License object
[out] myUrlCustomDb The result of the function. If the function encounters an error, an exception of type ExDca will be thrown that must be caught by the caller.

Definition at line 282 of file customdb_samples/customdbsample/main.cpp.

int ProcessCustomDatabase ( const DcaInstance aDca,
const License aLicense 
)

First calls InitializeCustomDatabase() with given parameters and then takes the following steps:

  • add an URL with categorizations to the custom database
  • retrieve the categories for that URL and print them out
  • removs the URL from the custom database
  • retry to retrieve the previously removed URL.

Parameters:
[in] aDca An already initialized DcaInstance object
[in] aLicense An already initialized License object
Returns:
0 in case of success
5 if getUrl() fails
6 if removeUrl() fails

Definition at line 342 of file customdb_samples/customdbsample/main.cpp.

int main ( int  argc,
char *  argv[] 
)

The main routine.

Parameters:
[in] argc The count of arguments provided
[in] argv An array of provided arguments
Returns:
1 on usage error
10 on exception
5, 6 if internal function fails
0 on success

Definition at line 406 of file customdb_samples/customdbsample/main.cpp.


Variable Documentation

const std::string S_UsageString
Initial value:
        "<redist-folder> <ticket> <product> <custom-db-folder> <categories-folder>\n"
        "  redist-folder - the folder where the DCA is installed to\n"
        "  ticket - a valid ticket\n"
        "  product - the product associated with your ticket\n"
        "  custom-db-folder - the folder where the Custom Database should be created in\n"
        "  categories-folder - the folder where your XML files are located in\n"

Usage string, displayed if a parameter is missing.

Definition at line 65 of file customdb_samples/customdbsample/main.cpp.


Generated on 26 Sep 2016 for dca_interface by  doxygen 1.6.1