Data Library

To be able to link directly with Data from a C++ application, the Data Library (C++ API) can be used.

A very basic example program using the Data Library looks like this:

#include <prolinga/Data.hpp>
                                                                                                                                             
int main(int argc, char **argv)
{
        /*Init */
        xmlDocPtr docReq, docRes;
        xmlNodePtr curReq, curRes;
        xmlBufferPtr bufRes;
        PlData dat;
                                                                                                                                             
        /* Open Data Environment */
        dat.dataOpen("./prolingadatcfg.xml", argc, argv);
                                                                                                                                             
        /* Create Data Command */
        docReq = xmlNewDoc((const xmlChar *)"1.0");
        docReq->children = xmlNewDocNode(docReq, NULL, (const xmlChar *)"ProLinga", NULL);
        curReq = xmlDocGetRootElement(docReq);
        curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Data", (const xmlChar *)"");
        xmlNewProp (curReq, (const xmlChar *)"Version", (const xmlChar *)"1.0");
        curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Command", (const xmlChar *)"");
        xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"Connect");
        xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request");
                                                                                                                                             
        /* Process Data Command */
        docRes = dat.executeCommand(docReq);
                                                                                                                                             
        /* Print Response */
        bufRes = xmlBufferCreate();
        curRes = xmlDocGetRootElement(docRes);
        xmlNodeDump(bufRes, docRes, curRes, 0, 1);
        printf("%s\n", (char *)xmlBufferContent(bufRes));
                                                                                                                                             
        /* Close Data Environment */
        dat.dataClose();
                                                                                                                                             
        /* Free */
        xmlBufferFree(bufRes);
        xmlFreeDoc(docRes);
        xmlFreeDoc(docReq);
                                                                                                                                             
        /* Return */
        return 0;
}

When running this application, a connection is made to the Data environment. When opening this connection an argument with the path and name of the data configuration file can be passed as an argument. The system then knows environment details. The configuration file has to be in a certain format, which is explained further on. The Data Command is then presented to the Data process engine and a response is returned. This response is printed to to stdout (screen). The connection to Data is closed and the program exits.

After creating a connection using the openData class function, more than one VC can be executed without the need to close and open the Data environment for every call. In fact performance wise this is the prefered method.

Note

The C API of the libxml2 toolkit has been used in this example, while it is probably better to use a C++ implementation of this toolkit as libxml++. Internal Data code will be changed as the project progresses.

To compile the program use the following command:

g++ data_test.cpp -o data_test `pkg-config --cflags --libs prolinga-data`

ProLinga-Data Library libprolingarepository has to be available for this option as well as the libgda libraries.

You may need to set the environment variable PKG_CONFIG_PATH to point to the directories where prolinga-data.pc is located. This can be directory /usr/lib/pkgconfig or directory /usr/local/lib/pkgconfig on Linux for example.

ProLinga-Data is built using various 3rd party open source packages. These packages need to be available at compile time for a sucessful result. See the dependencies and prerequisites section for more details.