Skip to content

The Code

Dusan Ciric edited this page Feb 25, 2020 · 11 revisions

Build and Understand the Code

The main intention with this section is to help a programmer to build and understand the platform code contained in rx-platform.

So, to start with the main function. This function is actually left out from the repository. It depends on your environment so no projects are uploaded. If you set your working environment correctly you just write the missing main function.

On GNU/Linux machines this is the main function example:

 // this is a linux platform
 #include "os_itf/linux/rx_linux.h"
 
 // a platform itself
 #include "rx_platform.h"

 // the host
 #include "host/gnu_hosts/rx_gnu_console.h"

int main(int argc, char* argv[])
{
    // create the storages
    storage::files::file_system_storage_holder system;
    storage::files::file_system_storage_holder user;
    storage::files::file_system_storage_holder test;
    hosting::rx_host_storages storages;
    storages.system_storage = &system;
    storages.user_storage = &user;
    storages.test_storage = &test;
    
    // create the host
    gnu::win32_console_host host(storages);
    // add plig-ins
    std::vector<library::rx_plugin_base*> plugins;

    protocols::modbus::rx_modbus_plugin modbus_plugin;
    plugins.emplace_back(&modbus_plugin);

    protocols::opc_ua::rx_opc_ua_plugin opc_ua_plugin;
    plugins.emplace_back(&opc_ua_plugin);
    // run console
    return host.console_main(argc, argv, plugins);
}

On Windows machines this is the main function example:

 // this is a windows platform 
 #include "os_itf/windows/rx_win.h"

 // a platform itself
 #include "rx_platform.h"

 // the host
 #include "host/win32_hosts/rx_win32_console.h"

int main(int argc, char* argv[])
{
    // create the storages
    storage::files::file_system_storage_holder system;
    storage::files::file_system_storage_holder user;
    storage::files::file_system_storage_holder test;
    hosting::rx_host_storages storages;
    storages.system_storage = &system;
    storages.user_storage = &user;
    storages.test_storage = &test;
    
    // create the host
    gnu::win32_console_host host(storages);
    // add plig-ins
    std::vector<library::rx_plugin_base*> plugins;

    protocols::modbus::rx_modbus_plugin modbus_plugin;
    plugins.emplace_back(&modbus_plugin);

    protocols::opc_ua::rx_opc_ua_plugin opc_ua_plugin;
    plugins.emplace_back(&opc_ua_plugin);
    // run console
    return host.console_main(argc, argv, plugins);
}