ProLinga-Repository Project |
---|
To be able to link directly into the Repository from a C++ application, the Repository Library (C++ API) can be used.
A very basic example program using the Repository Library, so it can access the Repository looks like this:
#include <prolinga/Repository.hpp> int main() { /*Init */ xmlDocPtr docReq, docRes; xmlNodePtr curReq, curRes; xmlBufferPtr bufRes; PlRepository rep; /* Open Repository Environment */ rep.repositoryOpen("./prolingarepcfg.xml"); /* Create Repository 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 *)"Repository", (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 *)"SysInfo"); xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request"); /* Process Repository Command */ docRes = rep.executeCommand(docReq); /* Print Response */ bufRes = xmlBufferCreate(); curRes = xmlDocGetRootElement(docRes); xmlNodeDump(bufRes, docRes, curRes, 0, 1); printf("%s\n", (char *)xmlBufferContent(bufRes)); /* Close Repository Environment */ rep.repositoryClose(); /* Free */ xmlBufferFree(bufRes); xmlFreeDoc(docRes); xmlFreeDoc(docReq); /* Return */ return 0; }
When running this application, a connection is made to the Repository. When opening this connection an argument with the path and name of the repository configuration file can be passed as an argument. The system then knows details as in which directory it can find the Repository files etc. The configuration file has to be in a certain format, which is explained further on. The Repository Command is then presented to the Repository process engine and a response is returned. This response is printed to to stdout (screen). The connection to Repository is closed, so data get flushed etc. and the program exits.
After creating a connection using the openRepository class function, more than one RC can be executed without the need to close and open the Repository for every call. In fact performance wise this is the prefered method.
To compile the program, use the following command:
g++ repository_test.cpp -o repository_test `pkg-config --cflags --libs prolinga-repository`
You may need to set the environment variable PKG_CONFIG_PATH to
point to the directories where prolinga-repository.pc is located.
This can be directory /usr/lib/pkgconfig
or
directory /usr/local/lib/pkgconfig
on GNU/Linux for
example.
ProLinga-Repository 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.
<< ProLinga-Repository Programming Notes | Download ProLinga-Repository >> |