Run Library

To be able to link directly into ProLinga-Run from a C++ application, the Run Library (C++ API) can be used.

A very basic example program using the Run Library, so it can access the 4GL interpreter looks like this:

#include <prolinga/Run.hpp>

int main(int argc, char *argv[])
{
        /*Init */
        xmlDocPtr docReq, docRes;
        xmlNodePtr curReq, curRes;
        xmlBufferPtr bufRes;
        PlRun run;

        /* Open Run Environment */
        run.runOpen("./prolingaruncfg.xml", argc, argv);

        /* Create Web 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 *)"Web", (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 *)"RunLogic");
        xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request");
        xmlNewProp (curReq, (const xmlChar *)"SessionId", (const xmlChar *)"None");
        xmlNewProp (curReq, (const xmlChar *)"Format", (const xmlChar *)"HTML");
        curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Object", (const xmlChar *)"");
        xmlNewProp (curReq, (const xmlChar *)"Service", (const xmlChar *)"Runner");
        xmlNewProp (curReq, (const xmlChar *)"Application", (const xmlChar *)"stock");
        xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"WPartLst");
        curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Parameters", (const xmlChar *)"");
        curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Parameter", (const xmlChar *)"ALL");
        xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"group_id");

        /* Process Web Command */
        docRes = run.executeCommand(docReq);

        /* Print Response */
        bufRes = xmlBufferCreate();
        curRes = xmlDocGetRootElement(docRes);
        xmlNodeDump(bufRes, docRes, curRes, 0, 1);
        printf("%s\n", (char *)xmlBufferContent(bufRes));

        /* Close Run Environment */
        run.runClose();

        /* Free */
        xmlBufferFree(bufRes);
        xmlFreeDoc(docRes);
        xmlFreeDoc(docReq);

        /* Return */
        return 0;
}

When opening this connection an argument with the path and name of the run configuration file can be passed as an argument. The system then knows details as in where it can connect to to find the Repository etc. The configuration file has to be in a certain format, which is explained further on. The Web Command is then presented to the Run process engine. Within this Run environment, the RunLogic command is called. Arguments are the service name that represents a hostname and portnumber, the name of the application to access and the name of the logic to execute. Additional parameters are parameters dependent on what the logic needs to be able to execute. After executing a response is returned. This response is printed to to stdout (screen). The connection to the Run environment is closed, so data get flushed etc. and the program exits.

After creating a connection using the openRun class function, more than one WC can be executed without the need to close and open the Run environment for every call. In fact performance wise this is the preferred 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 Run code will be changed as the project progresses.

To compile the program, use the following command:

g++ run_test.cpp -o run_test `pkg-config --cflags --libs prolinga-run`

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

ProLinga-Run 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.