| 81 | {{{ |
| 82 | #!cpp |
| 83 | void PingPong::startup() |
| 84 | { |
| 85 | using boost::property_tree::ptree; |
| 86 | using boost::property_tree::json_parser::read_json; |
| 87 | |
| 88 | logging_info( "[PINGPONG]\t starting up PingPong service ... " ); |
| 89 | |
| 90 | // read config |
| 91 | ptree config; |
| 92 | try |
| 93 | { |
| 94 | read_json(config_file, config); |
| 95 | } |
| 96 | catch ( exception& e ) |
| 97 | { |
| 98 | logging_warn("ERROR: Failed to read config file »" << config_file << "«: "); |
| 99 | logging_warn(e.what()); |
| 100 | logging_warn("---> Using fallback config."); |
| 101 | |
| 102 | config.put("ariba.spovnet_name", "pingpong"); |
| 103 | } |
| 104 | |
| 105 | // use node name also in the application |
| 106 | name = config.get("ariba.node_name", "NO_NAME"); |
| 107 | |
| 108 | // bind communication and node listener |
| 109 | node.bind( this ); /*NodeListener*/ |
| 110 | node.bind( this, PingPong::PINGPONG_SERVICEID); /*CommunicationListener*/ |
| 111 | |
| 112 | // connecting |
| 113 | logging_debug( "connecting ... " ); |
| 114 | |
| 115 | node.connect(config.get_child("ariba")); |
| 116 | |
| 117 | // ping pong started up... |
| 118 | logging_info( "[PINGPONG]\t pingpong starting up with" |
| 119 | << " [spovnetid " << node.getSpoVNetId().toString() << "]" |
| 120 | << " and [nodeid " << node.getNodeId().toString() << "]" ); |
| 121 | } |
| 122 | }}} |
| 123 | |
| 124 | - `ptree config;` is an yet empty instance of boost::property_tree::ptree. |
| 125 | - `read_json(config_file, config);` reads a config file (like the JSON file showed in the previous section) into the ptree instance `config`. The path of the JSON file is stored in `config_file`. |
| 126 | - If the read fails, the except handler prints a warning and initiates a default config directly within the code via: `config.put("ariba.spovnet_name", "pingpong");` |
| 127 | - The node variable is defined as attribute: `ariba::Node node;` (initialized with the standard constructor). Thoe follwing registers the callbacks from ariba: |
| 128 | - `node.bind( this );` |
| 129 | - `node.bind( this, PingPong::PINGPONG_SERVICEID);` |
| 130 | - The following command starts ariba with the config stored in the ptree |
| 131 | - `node.connect(config.get_child("ariba"));` |
| 132 | |
| 133 | The callbacks (functions in the application that are called from ariba) are declared in `ariba/CommunicationListener.h`. |
| 134 | The ariba interface (functions in ariba that can be called from the application) are declared in `ariba/Node.h`. |
| 135 | |