summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJuergen Gehring <juergen.gehring@bmw.de>2018-05-22 02:54:41 -0700
committerJuergen Gehring <juergen.gehring@bmw.de>2018-05-22 02:54:41 -0700
commit3f591262507bbce2a57e182ef8a1c40951a31018 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /examples
parent4808f3130c97cea3f0168005b9df029282060539 (diff)
downloadvSomeIP-3f591262507bbce2a57e182ef8a1c40951a31018.tar.gz
vsomeip 2.10.11 2.10.12 2.10.13 2.10.14 2.10.15 2.10.16 2.10.17 2.10.18 2.10.19 2.10.20 2.10.21
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt37
-rw-r--r--examples/hello_world/CMakeLists.txt27
-rw-r--r--examples/hello_world/hello_world_client.cpp161
-rw-r--r--examples/hello_world/hello_world_service.cpp155
-rw-r--r--examples/hello_world/helloworld-local.json36
-rw-r--r--examples/hello_world/readme48
-rw-r--r--examples/notify-sample.cpp260
-rw-r--r--examples/readme.txt17
-rw-r--r--examples/request-sample.cpp236
-rw-r--r--examples/response-sample.cpp187
-rw-r--r--examples/sample-ids.hpp23
-rw-r--r--examples/subscribe-sample.cpp189
12 files changed, 0 insertions, 1376 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
deleted file mode 100644
index 017c56d..0000000
--- a/examples/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-cmake_minimum_required (VERSION 2.8)
-
-set(EXAMPLE_CONFIG_FILES
- "../config/vsomeip.json"
- "../config/vsomeip-local.json"
- "../config/vsomeip-tcp-client.json"
- "../config/vsomeip-tcp-service.json"
- "../config/vsomeip-udp-client.json"
- "../config/vsomeip-udp-service.json"
-)
-
-# Examples
-add_executable(request-sample request-sample.cpp ${EXAMPLE_CONFIG_FILES})
-target_link_libraries(request-sample vsomeip ${Boost_LIBRARIES} ${DL_LIBRARY})
-
-add_executable(response-sample response-sample.cpp ${EXAMPLE_CONFIG_FILES})
-target_link_libraries(response-sample vsomeip ${Boost_LIBRARIES} ${DL_LIBRARY})
-
-add_executable(subscribe-sample subscribe-sample.cpp ${EXAMPLE_CONFIG_FILES})
-target_link_libraries(subscribe-sample vsomeip ${Boost_LIBRARIES} ${DL_LIBRARY})
-
-add_executable(notify-sample notify-sample.cpp ${EXAMPLE_CONFIG_FILES})
-target_link_libraries(notify-sample vsomeip ${Boost_LIBRARIES} ${DL_LIBRARY})
-
-add_dependencies(examples request-sample response-sample subscribe-sample notify-sample)
-
-install (
- TARGETS request-sample response-sample subscribe-sample notify-sample
- RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
-)
-
-###################################################################################################
diff --git a/examples/hello_world/CMakeLists.txt b/examples/hello_world/CMakeLists.txt
deleted file mode 100644
index b7f7c78..0000000
--- a/examples/hello_world/CMakeLists.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-cmake_minimum_required (VERSION 2.8.7)
-project (vSomeIPHelloWorld)
-
-# This will get us acces to
-# VSOMEIP_INCLUDE_DIRS - include directories for vSomeIP
-# VSOMEIP_LIBRARIES - libraries to link against
-find_package(vsomeip)
-if (NOT vsomeip_FOUND)
- message("vsomeip was not found. Please specify vsomeip_DIR")
-endif()
-
-find_package(Threads REQUIRED)
-
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-
-include_directories(${VSOMEIP_INCLUDE_DIRS})
-
-add_executable (hello_world_service hello_world_service.cpp)
-target_link_libraries(hello_world_service ${VSOMEIP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
-
-add_executable (hello_world_client hello_world_client.cpp)
-target_link_libraries(hello_world_client ${VSOMEIP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
diff --git a/examples/hello_world/hello_world_client.cpp b/examples/hello_world/hello_world_client.cpp
deleted file mode 100644
index cecdf67..0000000
--- a/examples/hello_world/hello_world_client.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
-#include <csignal>
-#endif
-#include <vsomeip/vsomeip.hpp>
-#include <iostream>
-
-static vsomeip::service_t service_id = 0x1111;
-static vsomeip::instance_t service_instance_id = 0x2222;
-static vsomeip::method_t service_method_id = 0x3333;
-
-class hello_world_client {
-public:
- // Get the vSomeIP runtime and
- // create a application via the runtime, we could pass the application name
- // here otherwise the name supplied via the VSOMEIP_APPLICATION_NAME
- // environment variable is used
- hello_world_client() :
- rtm_(vsomeip::runtime::get()),
- app_(rtm_->create_application())
- {
- }
-
- bool init(){
- // init the application
- if (!app_->init()) {
- std::cerr << "Couldn't initialize application" << std::endl;
- return false;
- }
-
- // register a state handler to get called back after registration at the
- // runtime was successful
- app_->register_state_handler(
- std::bind(&hello_world_client::on_state_cbk, this,
- std::placeholders::_1));
-
- // register a callback for responses from the service
- app_->register_message_handler(vsomeip::ANY_SERVICE,
- service_instance_id, vsomeip::ANY_METHOD,
- std::bind(&hello_world_client::on_message_cbk, this,
- std::placeholders::_1));
-
- // register a callback which is called as soon as the service is available
- app_->register_availability_handler(service_id, service_instance_id,
- std::bind(&hello_world_client::on_availability_cbk, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3));
- return true;
- }
-
- void start()
- {
- // start the application and wait for the on_event callback to be called
- // this method only returns when app_->stop() is called
- app_->start();
- }
-
- void on_state_cbk(vsomeip::state_type_e _state)
- {
- if(_state == vsomeip::state_type_e::ST_REGISTERED)
- {
- // we are registered at the runtime now we can request the service
- // and wait for the on_availability callback to be called
- app_->request_service(service_id, service_instance_id);
- }
- }
-
- void on_availability_cbk(vsomeip::service_t _service,
- vsomeip::instance_t _instance, bool _is_available)
- {
- // Check if the available service is the the hello world service
- if(service_id == _service && service_instance_id == _instance
- && _is_available)
- {
- // The service is available then we send the request
- // Create a new request
- std::shared_ptr<vsomeip::message> rq = rtm_->create_request();
- // Set the hello world service as target of the request
- rq->set_service(service_id);
- rq->set_instance(service_instance_id);
- rq->set_method(service_method_id);
-
- // Create a payload which will be sent to the service
- std::shared_ptr<vsomeip::payload> pl = rtm_->create_payload();
- std::string str("World");
- std::vector<vsomeip::byte_t> pl_data(std::begin(str), std::end(str));
-
- pl->set_data(pl_data);
- rq->set_payload(pl);
- // Send the request to the service. Response will be delivered to the
- // registered message handler
- std::cout << "Sending: " << str << std::endl;
- app_->send(rq, true);
- }
- }
-
- void on_message_cbk(const std::shared_ptr<vsomeip::message> &_response)
- {
- if(service_id == _response->get_service()
- && service_instance_id == _response->get_instance()
- && vsomeip::message_type_e::MT_RESPONSE
- == _response->get_message_type()
- && vsomeip::return_code_e::E_OK == _response->get_return_code())
- {
- // Get the payload and print it
- std::shared_ptr<vsomeip::payload> pl = _response->get_payload();
- std::string resp = std::string(
- reinterpret_cast<const char*>(pl->get_data()), 0,
- pl->get_length());
- std::cout << "Received: " << resp << std::endl;
- stop();
- }
- }
-
- void stop()
- {
- // unregister the state handler
- app_->unregister_state_handler();
- // unregister the message handler
- app_->unregister_message_handler(vsomeip::ANY_SERVICE,
- service_instance_id, vsomeip::ANY_METHOD);
- // alternatively unregister all registered handlers at once
- app_->clear_all_handler();
- // release the service
- app_->release_service(service_id, service_instance_id);
- // shutdown the application
- app_->stop();
- }
-
-private:
- std::shared_ptr<vsomeip::runtime> rtm_;
- std::shared_ptr<vsomeip::application> app_;
-};
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
-hello_world_client *hw_cl_ptr(nullptr);
- void handle_signal(int _signal) {
- if (hw_cl_ptr != nullptr &&
- (_signal == SIGINT || _signal == SIGTERM))
- hw_cl_ptr->stop();
- }
-#endif
-
-int main(int argc, char **argv)
-{
- hello_world_client hw_cl;
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- hw_cl_ptr = &hw_cl;
- signal(SIGINT, handle_signal);
- signal(SIGTERM, handle_signal);
-#endif
- if (hw_cl.init()) {
- hw_cl.start();
- return 0;
- } else {
- return 1;
- }
-}
diff --git a/examples/hello_world/hello_world_service.cpp b/examples/hello_world/hello_world_service.cpp
deleted file mode 100644
index 7af031c..0000000
--- a/examples/hello_world/hello_world_service.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
-#include <csignal>
-#endif
-#include <vsomeip/vsomeip.hpp>
-#include <chrono>
-#include <thread>
-#include <condition_variable>
-#include <mutex>
-#include <iostream>
-
-static vsomeip::service_t service_id = 0x1111;
-static vsomeip::instance_t service_instance_id = 0x2222;
-static vsomeip::method_t service_method_id = 0x3333;
-
-class hello_world_service {
-public:
- // Get the vSomeIP runtime and
- // create a application via the runtime, we could pass the application name
- // here otherwise the name supplied via the VSOMEIP_APPLICATION_NAME
- // environment variable is used
- hello_world_service() :
- rtm_(vsomeip::runtime::get()),
- app_(rtm_->create_application()),
- stop_(false),
- stop_thread_(std::bind(&hello_world_service::stop, this))
- {
- }
-
- ~hello_world_service()
- {
- stop_thread_.join();
- }
-
- bool init()
- {
- // init the application
- if (!app_->init()) {
- std::cerr << "Couldn't initialize application" << std::endl;
- return false;
- }
-
- // register a message handler callback for messages sent to our service
- app_->register_message_handler(service_id, service_instance_id,
- service_method_id,
- std::bind(&hello_world_service::on_message_cbk, this,
- std::placeholders::_1));
-
- // register a state handler to get called back after registration at the
- // runtime was successful
- app_->register_state_handler(
- std::bind(&hello_world_service::on_state_cbk, this,
- std::placeholders::_1));
- return true;
- }
-
- void start()
- {
- // start the application and wait for the on_event callback to be called
- // this method only returns when app_->stop() is called
- app_->start();
- }
-
- void stop()
- {
- std::unique_lock<std::mutex> its_lock(mutex_);
- while(!stop_) {
- condition_.wait(its_lock);
- }
- std::this_thread::sleep_for(std::chrono::seconds(5));
- // Stop offering the service
- app_->stop_offer_service(service_id, service_instance_id);
- // unregister the state handler
- app_->unregister_state_handler();
- // unregister the message handler
- app_->unregister_message_handler(service_id, service_instance_id,
- service_method_id);
- // shutdown the application
- app_->stop();
- }
-
- void terminate() {
- std::lock_guard<std::mutex> its_lock(mutex_);
- stop_ = true;
- condition_.notify_one();
- }
-
- void on_state_cbk(vsomeip::state_type_e _state)
- {
- if(_state == vsomeip::state_type_e::ST_REGISTERED)
- {
- // we are registered at the runtime and can offer our service
- app_->offer_service(service_id, service_instance_id);
- }
- }
-
- void on_message_cbk(const std::shared_ptr<vsomeip::message> &_request)
- {
- // Create a response based upon the request
- std::shared_ptr<vsomeip::message> resp = rtm_->create_response(_request);
-
- // Construct string to send back
- std::string str("Hello ");
- str.append(
- reinterpret_cast<const char*>(_request->get_payload()->get_data()),
- 0, _request->get_payload()->get_length());
-
- // Create a payload which will be sent back to the client
- std::shared_ptr<vsomeip::payload> resp_pl = rtm_->create_payload();
- std::vector<vsomeip::byte_t> pl_data(str.begin(), str.end());
- resp_pl->set_data(pl_data);
- resp->set_payload(resp_pl);
-
- // Send the response back
- app_->send(resp, true);
- // we have finished
- terminate();
- }
-
-private:
- std::shared_ptr<vsomeip::runtime> rtm_;
- std::shared_ptr<vsomeip::application> app_;
- bool stop_;
- std::mutex mutex_;
- std::condition_variable condition_;
- std::thread stop_thread_;
-};
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
-hello_world_service *hw_srv_ptr(nullptr);
- void handle_signal(int _signal) {
- if (hw_srv_ptr != nullptr &&
- (_signal == SIGINT || _signal == SIGTERM))
- hw_srv_ptr->terminate();
- }
-#endif
-
-int main(int argc, char **argv)
-{
- hello_world_service hw_srv;
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- hw_srv_ptr = &hw_srv;
- signal(SIGINT, handle_signal);
- signal(SIGTERM, handle_signal);
-#endif
- if (hw_srv.init()) {
- hw_srv.start();
- return 0;
- } else {
- return 1;
- }
-}
diff --git a/examples/hello_world/helloworld-local.json b/examples/hello_world/helloworld-local.json
deleted file mode 100644
index 5aeebb7..0000000
--- a/examples/hello_world/helloworld-local.json
+++ /dev/null
@@ -1,36 +0,0 @@
-{
- "unicast":"134.86.56.94",
- "logging":
- {
- "level":"debug",
- "console":"true"
- },
-
- "applications":
- [
- {
- "name":"hello_world_service",
- "id":"0x4444"
- },
-
- {
- "name":"hello_world_client",
- "id":"0x5555"
- }
- ],
-
- "services":
- [
- {
- "service":"0x1111",
- "instance":"0x2222",
- "unreliable":"30509"
- }
- ],
-
- "routing":"hello_world_service",
- "service-discovery":
- {
- "enable":"false"
- }
-}
diff --git a/examples/hello_world/readme b/examples/hello_world/readme
deleted file mode 100644
index 3e1dc62..0000000
--- a/examples/hello_world/readme
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-Build instructions for Hello World example
-------------------------------------------
-
-mkdir build
-cd build
-cmake ..
-make
-
-Running Hello World Example
----------------------------
-
-The Hello World Example should be run on the same host.
-The network addresses within the configuration files need to be adapted to match
-the devices addresses.
-
-To start the hello world client and service from their build-directory do:
-
-HOST1:
-VSOMEIP_CONFIGURATION=../helloworld-local.json \
-VSOMEIP_APPLICATION_NAME=hello_world_service \
-./hello_world_service
-
-HOST1:
-VSOMEIP_CONFIGURATION=../helloworld-local.json \
-VSOMEIP_APPLICATION_NAME=hello_world_client \
-./hello_world_client
-
-Expected output service
------------------------
-2015-04-01 11:31:13.248437 [info] Using configuration file: ../helloworld-local.json
-2015-04-01 11:31:13.248766 [debug] Routing endpoint at /tmp/vsomeip-0
-2015-04-01 11:31:13.248913 [info] Service Discovery disabled. Using static routing information.
-2015-04-01 11:31:13.248979 [debug] Application(hello_world_service, 4444) is initialized.
-2015-04-01 11:31:22.705010 [debug] Application/Client 5555 got registered!
-
-Expected output client
-----------------------
-2015-04-01 11:31:22.704166 [info] Using configuration file: ../helloworld-local.json
-2015-04-01 11:31:22.704417 [debug] Connecting to [0] at /tmp/vsomeip-0
-2015-04-01 11:31:22.704630 [debug] Listening at /tmp/vsomeip-5555
-2015-04-01 11:31:22.704680 [debug] Application(hello_world_client, 5555) is initialized.
-Sending: World
-Received: Hello World
diff --git a/examples/notify-sample.cpp b/examples/notify-sample.cpp
deleted file mode 100644
index 1bcd219..0000000
--- a/examples/notify-sample.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
-#include <csignal>
-#endif
-#include <chrono>
-#include <condition_variable>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <thread>
-
-#include <vsomeip/vsomeip.hpp>
-
-#include "sample-ids.hpp"
-
-class service_sample {
-public:
- service_sample(bool _use_tcp, uint32_t _cycle) :
- app_(vsomeip::runtime::get()->create_application()),
- is_registered_(false),
- use_tcp_(_use_tcp),
- cycle_(_cycle),
- blocked_(false),
- running_(true),
- is_offered_(false),
- offer_thread_(std::bind(&service_sample::run, this)),
- notify_thread_(std::bind(&service_sample::notify, this)) {
- }
-
- bool init() {
- std::lock_guard<std::mutex> its_lock(mutex_);
-
- if (!app_->init()) {
- std::cerr << "Couldn't initialize application" << std::endl;
- return false;
- }
- app_->register_state_handler(
- std::bind(&service_sample::on_state, this,
- std::placeholders::_1));
-
- app_->register_message_handler(
- SAMPLE_SERVICE_ID,
- SAMPLE_INSTANCE_ID,
- SAMPLE_GET_METHOD_ID,
- std::bind(&service_sample::on_get, this,
- std::placeholders::_1));
-
- app_->register_message_handler(
- SAMPLE_SERVICE_ID,
- SAMPLE_INSTANCE_ID,
- SAMPLE_SET_METHOD_ID,
- std::bind(&service_sample::on_set, this,
- std::placeholders::_1));
-
- std::set<vsomeip::eventgroup_t> its_groups;
- its_groups.insert(SAMPLE_EVENTGROUP_ID);
- app_->offer_event(
- SAMPLE_SERVICE_ID,
- SAMPLE_INSTANCE_ID,
- SAMPLE_EVENT_ID,
- its_groups,
- true);
- payload_ = vsomeip::runtime::get()->create_payload();
-
- blocked_ = true;
- condition_.notify_one();
- return true;
- }
-
- void start() {
- app_->start();
- }
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- /*
- * Handle signal to shutdown
- */
- void stop() {
- running_ = false;
- blocked_ = true;
- condition_.notify_one();
- notify_condition_.notify_one();
- app_->clear_all_handler();
- stop_offer();
- offer_thread_.join();
- notify_thread_.join();
- app_->stop();
- }
-#endif
-
- void offer() {
- std::lock_guard<std::mutex> its_lock(notify_mutex_);
- app_->offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
- is_offered_ = true;
- notify_condition_.notify_one();
- }
-
- void stop_offer() {
- app_->stop_offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
- is_offered_ = false;
- }
-
- void on_state(vsomeip::state_type_e _state) {
- std::cout << "Application " << app_->get_name() << " is "
- << (_state == vsomeip::state_type_e::ST_REGISTERED ?
- "registered." : "deregistered.") << std::endl;
-
- if (_state == vsomeip::state_type_e::ST_REGISTERED) {
- if (!is_registered_) {
- is_registered_ = true;
- }
- } else {
- is_registered_ = false;
- }
- }
-
- void on_get(const std::shared_ptr<vsomeip::message> &_message) {
- std::shared_ptr<vsomeip::message> its_response
- = vsomeip::runtime::get()->create_response(_message);
- its_response->set_payload(payload_);
- app_->send(its_response, true);
- }
-
- void on_set(const std::shared_ptr<vsomeip::message> &_message) {
- payload_ = _message->get_payload();
-
- std::shared_ptr<vsomeip::message> its_response
- = vsomeip::runtime::get()->create_response(_message);
- its_response->set_payload(payload_);
- app_->send(its_response, true);
- app_->notify(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID,
- SAMPLE_EVENT_ID, payload_);
- }
-
- void run() {
- std::unique_lock<std::mutex> its_lock(mutex_);
- while (!blocked_)
- condition_.wait(its_lock);
-
- bool is_offer(true);
- while (running_) {
- if (is_offer)
- offer();
- else
- stop_offer();
-
- for (int i = 0; i < 10 && running_; i++)
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
-
- is_offer = !is_offer;
- }
- }
-
- void notify() {
- std::shared_ptr<vsomeip::message> its_message
- = vsomeip::runtime::get()->create_request(use_tcp_);
-
- its_message->set_service(SAMPLE_SERVICE_ID);
- its_message->set_instance(SAMPLE_INSTANCE_ID);
- its_message->set_method(SAMPLE_SET_METHOD_ID);
-
- vsomeip::byte_t its_data[10];
- uint32_t its_size = 1;
-
- while (running_) {
- std::unique_lock<std::mutex> its_lock(notify_mutex_);
- while (!is_offered_ && running_)
- notify_condition_.wait(its_lock);
- while (is_offered_ && running_) {
- if (its_size == sizeof(its_data))
- its_size = 1;
-
- for (uint32_t i = 0; i < its_size; ++i)
- its_data[i] = static_cast<uint8_t>(i);
-
- payload_->set_data(its_data, its_size);
-
- std::cout << "Setting event (Length=" << std::dec << its_size << ")." << std::endl;
- app_->notify(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, payload_);
-
- its_size++;
-
- std::this_thread::sleep_for(std::chrono::milliseconds(cycle_));
- }
- }
- }
-
-private:
- std::shared_ptr<vsomeip::application> app_;
- bool is_registered_;
- bool use_tcp_;
- uint32_t cycle_;
-
- std::mutex mutex_;
- std::condition_variable condition_;
- bool blocked_;
- bool running_;
-
- std::mutex notify_mutex_;
- std::condition_variable notify_condition_;
- bool is_offered_;
-
- std::shared_ptr<vsomeip::payload> payload_;
-
- // blocked_ / is_offered_ must be initialized before starting the threads!
- std::thread offer_thread_;
- std::thread notify_thread_;
-};
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- service_sample *its_sample_ptr(nullptr);
- void handle_signal(int _signal) {
- if (its_sample_ptr != nullptr &&
- (_signal == SIGINT || _signal == SIGTERM))
- its_sample_ptr->stop();
- }
-#endif
-
-int main(int argc, char **argv) {
- bool use_tcp = false;
- uint32_t cycle = 1000; // default 1s
-
- std::string tcp_enable("--tcp");
- std::string udp_enable("--udp");
- std::string cycle_arg("--cycle");
-
- for (int i = 1; i < argc; i++) {
- if (tcp_enable == argv[i]) {
- use_tcp = true;
- break;
- }
- if (udp_enable == argv[i]) {
- use_tcp = false;
- break;
- }
-
- if (cycle_arg == argv[i] && i + 1 < argc) {
- i++;
- std::stringstream converter;
- converter << argv[i];
- converter >> cycle;
- }
- }
-
- service_sample its_sample(use_tcp, cycle);
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- its_sample_ptr = &its_sample;
- signal(SIGINT, handle_signal);
- signal(SIGTERM, handle_signal);
-#endif
- if (its_sample.init()) {
- its_sample.start();
- return 0;
- } else {
- return 1;
- }
-}
diff --git a/examples/readme.txt b/examples/readme.txt
deleted file mode 100644
index 219df9b..0000000
--- a/examples/readme.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-To use the example applications you need two devices on the same network. The network addresses within
-the configuration files need to be adapted to match the devices addresses.
-
-To start the request/response-example from the build-directory do:
-
-HOST1: env VSOMEIP_CONFIGURATION=../../config/vsomeip-local.json VSOMEIP_APPLICATION_NAME=client-sample ./request-sample
-HOST1: env VSOMEIP_CONFIGURATION=../../config/vsomeip-local.json VSOMEIP_APPLICATION_NAME=service-sample ./response-sample
-
-To start the subscribe/notify-example from the build-directory do:
-
-HOST1: env VSOMEIP_CONFIGURATION=../../config/vsomeip-local.json VSOMEIP_APPLICATION_NAME=client-sample ./subscribe-sample
-HOST1: env VSOMEIP_CONFIGURATION=../../config/vsomeip-local.json VSOMEIP_APPLICATION_NAME=service-sample ./notify-sample
diff --git a/examples/request-sample.cpp b/examples/request-sample.cpp
deleted file mode 100644
index 7732cb0..0000000
--- a/examples/request-sample.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
-#include <csignal>
-#endif
-#include <chrono>
-#include <condition_variable>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <thread>
-
-#include <vsomeip/vsomeip.hpp>
-
-#include "sample-ids.hpp"
-
-class client_sample {
-public:
- client_sample(bool _use_tcp, bool _be_quiet, uint32_t _cycle)
- : app_(vsomeip::runtime::get()->create_application()),
- request_(vsomeip::runtime::get()->create_request(_use_tcp)),
- use_tcp_(_use_tcp),
- be_quiet_(_be_quiet),
- cycle_(_cycle),
- running_(true),
- blocked_(false),
- is_available_(false),
- sender_(std::bind(&client_sample::run, this)) {
- }
-
- bool init() {
- if (!app_->init()) {
- std::cerr << "Couldn't initialize application" << std::endl;
- return false;
- }
-
- std::cout << "Client settings [protocol="
- << (use_tcp_ ? "TCP" : "UDP")
- << ":quiet="
- << (be_quiet_ ? "true" : "false")
- << ":cycle="
- << cycle_
- << "]"
- << std::endl;
-
- app_->register_state_handler(
- std::bind(
- &client_sample::on_state,
- this,
- std::placeholders::_1));
-
- app_->register_message_handler(
- vsomeip::ANY_SERVICE, SAMPLE_INSTANCE_ID, vsomeip::ANY_METHOD,
- std::bind(&client_sample::on_message,
- this,
- std::placeholders::_1));
-
- request_->set_service(SAMPLE_SERVICE_ID);
- request_->set_instance(SAMPLE_INSTANCE_ID);
- request_->set_method(SAMPLE_METHOD_ID);
-
- std::shared_ptr< vsomeip::payload > its_payload = vsomeip::runtime::get()->create_payload();
- std::vector< vsomeip::byte_t > its_payload_data;
- for (std::size_t i = 0; i < 10; ++i) its_payload_data.push_back(i % 256);
- its_payload->set_data(its_payload_data);
- request_->set_payload(its_payload);
-
- app_->register_availability_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID,
- std::bind(&client_sample::on_availability,
- this,
- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
-
- app_->register_availability_handler(SAMPLE_SERVICE_ID + 1, SAMPLE_INSTANCE_ID,
- std::bind(&client_sample::on_availability,
- this,
- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
- return true;
- }
-
- void start() {
- app_->start();
- }
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- /*
- * Handle signal to shutdown
- */
- void stop() {
- running_ = false;
- blocked_ = true;
- app_->clear_all_handler();
- app_->release_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
- condition_.notify_one();
- sender_.join();
- app_->stop();
- }
-#endif
-
- void on_state(vsomeip::state_type_e _state) {
- if (_state == vsomeip::state_type_e::ST_REGISTERED) {
- app_->request_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
- }
- }
-
- void on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
- std::cout << "Service ["
- << std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
- << "] is "
- << (_is_available ? "available." : "NOT available.")
- << std::endl;
-
- if (SAMPLE_SERVICE_ID == _service && SAMPLE_INSTANCE_ID == _instance) {
- if (is_available_ && !_is_available) {
- is_available_ = false;
- } else if (_is_available && !is_available_) {
- is_available_ = true;
- send();
- }
- }
- }
-
- void on_message(const std::shared_ptr< vsomeip::message > &_response) {
- std::cout << "Received a response from Service ["
- << std::setw(4) << std::setfill('0') << std::hex << _response->get_service()
- << "."
- << std::setw(4) << std::setfill('0') << std::hex << _response->get_instance()
- << "] to Client/Session ["
- << std::setw(4) << std::setfill('0') << std::hex << _response->get_client()
- << "/"
- << std::setw(4) << std::setfill('0') << std::hex << _response->get_session()
- << "]"
- << std::endl;
- if (is_available_)
- send();
- }
-
- void send() {
- if (!be_quiet_)
- {
- std::lock_guard< std::mutex > its_lock(mutex_);
- blocked_ = true;
- condition_.notify_one();
- }
- }
-
- void run() {
- while (running_) {
- {
- std::unique_lock<std::mutex> its_lock(mutex_);
- while (!blocked_) condition_.wait(its_lock);
- if (is_available_) {
- app_->send(request_, true);
- std::cout << "Client/Session ["
- << std::setw(4) << std::setfill('0') << std::hex << request_->get_client()
- << "/"
- << std::setw(4) << std::setfill('0') << std::hex << request_->get_session()
- << "] sent a request to Service ["
- << std::setw(4) << std::setfill('0') << std::hex << request_->get_service()
- << "."
- << std::setw(4) << std::setfill('0') << std::hex << request_->get_instance()
- << "]"
- << std::endl;
- blocked_ = false;
- }
- }
- std::this_thread::sleep_for(std::chrono::milliseconds(cycle_));
- }
- }
-
-private:
- std::shared_ptr< vsomeip::application > app_;
- std::shared_ptr< vsomeip::message > request_;
- bool use_tcp_;
- bool be_quiet_;
- uint32_t cycle_;
- vsomeip::session_t session_;
- std::mutex mutex_;
- std::condition_variable condition_;
- bool running_;
- bool blocked_;
- bool is_available_;
-
- std::thread sender_;
-};
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- client_sample *its_sample_ptr(nullptr);
- void handle_signal(int _signal) {
- if (its_sample_ptr != nullptr &&
- (_signal == SIGINT || _signal == SIGTERM))
- its_sample_ptr->stop();
- }
-#endif
-
-int main(int argc, char **argv) {
- bool use_tcp = false;
- bool be_quiet = false;
- uint32_t cycle = 1000; // Default: 1s
-
- std::string tcp_enable("--tcp");
- std::string udp_enable("--udp");
- std::string quiet_enable("--quiet");
- std::string cycle_arg("--cycle");
-
- int i = 1;
- while (i < argc) {
- if (tcp_enable == argv[i]) {
- use_tcp = true;
- } else if (udp_enable == argv[i]) {
- use_tcp = false;
- } else if (quiet_enable == argv[i]) {
- be_quiet = true;
- } else if (cycle_arg == argv[i] && i+1 < argc) {
- i++;
- std::stringstream converter;
- converter << argv[i];
- converter >> cycle;
- }
- i++;
- }
-
- client_sample its_sample(use_tcp, be_quiet, cycle);
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- its_sample_ptr = &its_sample;
- signal(SIGINT, handle_signal);
- signal(SIGTERM, handle_signal);
-#endif
- if (its_sample.init()) {
- its_sample.start();
- return 0;
- } else {
- return 1;
- }
-}
diff --git a/examples/response-sample.cpp b/examples/response-sample.cpp
deleted file mode 100644
index b4b6250..0000000
--- a/examples/response-sample.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
-#include <csignal>
-#endif
-#include <chrono>
-#include <condition_variable>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <thread>
-
-#include <vsomeip/vsomeip.hpp>
-
-#include "sample-ids.hpp"
-
-class service_sample {
-public:
- service_sample(bool _use_static_routing) :
- app_(vsomeip::runtime::get()->create_application()),
- is_registered_(false),
- use_static_routing_(_use_static_routing),
- blocked_(false),
- running_(true),
- offer_thread_(std::bind(&service_sample::run, this)) {
- }
-
- bool init() {
- std::lock_guard<std::mutex> its_lock(mutex_);
-
- if (!app_->init()) {
- std::cerr << "Couldn't initialize application" << std::endl;
- return false;
- }
- app_->register_state_handler(
- std::bind(&service_sample::on_state, this,
- std::placeholders::_1));
- app_->register_message_handler(
- SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID,
- std::bind(&service_sample::on_message, this,
- std::placeholders::_1));
-
- std::cout << "Static routing " << (use_static_routing_ ? "ON" : "OFF")
- << std::endl;
- return true;
- }
-
- void start() {
- app_->start();
- }
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- /*
- * Handle signal to shutdown
- */
- void stop() {
- running_ = false;
- blocked_ = true;
- app_->clear_all_handler();
- stop_offer();
- condition_.notify_one();
- offer_thread_.join();
- app_->stop();
- }
-#endif
-
- void offer() {
- app_->offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
- app_->offer_service(SAMPLE_SERVICE_ID + 1, SAMPLE_INSTANCE_ID);
- }
-
- void stop_offer() {
- app_->stop_offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
- app_->stop_offer_service(SAMPLE_SERVICE_ID + 1, SAMPLE_INSTANCE_ID);
- }
-
- void on_state(vsomeip::state_type_e _state) {
- std::cout << "Application " << app_->get_name() << " is "
- << (_state == vsomeip::state_type_e::ST_REGISTERED ?
- "registered." : "deregistered.")
- << std::endl;
-
- if (_state == vsomeip::state_type_e::ST_REGISTERED) {
- if (!is_registered_) {
- is_registered_ = true;
- blocked_ = true;
- condition_.notify_one();
- }
- } else {
- is_registered_ = false;
- }
- }
-
- void on_message(const std::shared_ptr<vsomeip::message> &_request) {
- std::cout << "Received a message with Client/Session [" << std::setw(4)
- << std::setfill('0') << std::hex << _request->get_client() << "/"
- << std::setw(4) << std::setfill('0') << std::hex
- << _request->get_session() << "]"
- << std::endl;
-
- std::shared_ptr<vsomeip::message> its_response
- = vsomeip::runtime::get()->create_response(_request);
-
- std::shared_ptr<vsomeip::payload> its_payload
- = vsomeip::runtime::get()->create_payload();
- std::vector<vsomeip::byte_t> its_payload_data;
- for (std::size_t i = 0; i < 120; ++i)
- its_payload_data.push_back(i % 256);
- its_payload->set_data(its_payload_data);
- its_response->set_payload(its_payload);
-
- app_->send(its_response, true);
- }
-
- void run() {
- std::unique_lock<std::mutex> its_lock(mutex_);
- while (!blocked_)
- condition_.wait(its_lock);
-
- bool is_offer(true);
-
- if (use_static_routing_) {
- offer();
- while (running_);
- } else {
- while (running_) {
- if (is_offer)
- offer();
- else
- stop_offer();
-
- for (int i = 0; i < 10 && running_; i++)
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- is_offer = !is_offer;
- }
- }
- }
-
-private:
- std::shared_ptr<vsomeip::application> app_;
- bool is_registered_;
- bool use_static_routing_;
-
- std::mutex mutex_;
- std::condition_variable condition_;
- bool blocked_;
- bool running_;
-
- // blocked_ must be initialized before the thread is started.
- std::thread offer_thread_;
-};
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- service_sample *its_sample_ptr(nullptr);
- void handle_signal(int _signal) {
- if (its_sample_ptr != nullptr &&
- (_signal == SIGINT || _signal == SIGTERM))
- its_sample_ptr->stop();
- }
-#endif
-
-int main(int argc, char **argv) {
- bool use_static_routing(false);
-
- std::string static_routing_enable("--static-routing");
-
- for (int i = 1; i < argc; i++) {
- if (static_routing_enable == argv[i]) {
- use_static_routing = true;
- }
- }
-
- service_sample its_sample(use_static_routing);
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- its_sample_ptr = &its_sample;
- signal(SIGINT, handle_signal);
- signal(SIGTERM, handle_signal);
-#endif
- if (its_sample.init()) {
- its_sample.start();
- return 0;
- } else {
- return 1;
- }
-}
diff --git a/examples/sample-ids.hpp b/examples/sample-ids.hpp
deleted file mode 100644
index 6d31131..0000000
--- a/examples/sample-ids.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef VSOMEIP_EXAMPLES_SAMPLE_IDS_HPP
-#define VSOMEIP_EXAMPLES_SAMPLE_IDS_HPP
-
-#define SAMPLE_SERVICE_ID 0x1234
-#define SAMPLE_INSTANCE_ID 0x5678
-#define SAMPLE_METHOD_ID 0x0421
-
-#define SAMPLE_EVENT_ID 0x8778
-#define SAMPLE_GET_METHOD_ID 0x0001
-#define SAMPLE_SET_METHOD_ID 0x0002
-
-#define SAMPLE_EVENTGROUP_ID 0x4465
-
-#define OTHER_SAMPLE_SERVICE_ID 0x0248
-#define OTHER_SAMPLE_INSTANCE_ID 0x5422
-#define OTHER_SAMPLE_METHOD_ID 0x1421
-
-#endif // VSOMEIP_EXAMPLES_SAMPLE_IDS_HPP
diff --git a/examples/subscribe-sample.cpp b/examples/subscribe-sample.cpp
deleted file mode 100644
index 5350263..0000000
--- a/examples/subscribe-sample.cpp
+++ /dev/null
@@ -1,189 +0,0 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
-#include <csignal>
-#endif
-#include <chrono>
-#include <condition_variable>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <thread>
-
-#include <vsomeip/vsomeip.hpp>
-
-#include "sample-ids.hpp"
-
-class client_sample {
-public:
- client_sample(bool _use_tcp) :
- app_(vsomeip::runtime::get()->create_application()), use_tcp_(
- _use_tcp) {
- }
-
- bool init() {
- if (!app_->init()) {
- std::cerr << "Couldn't initialize application" << std::endl;
- return false;
- }
- std::cout << "Client settings [protocol="
- << (use_tcp_ ? "TCP" : "UDP")
- << "]"
- << std::endl;
-
- app_->register_state_handler(
- std::bind(&client_sample::on_state, this,
- std::placeholders::_1));
-
- app_->register_message_handler(
- vsomeip::ANY_SERVICE, SAMPLE_INSTANCE_ID, vsomeip::ANY_METHOD,
- std::bind(&client_sample::on_message, this,
- std::placeholders::_1));
-
- app_->register_availability_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID,
- std::bind(&client_sample::on_availability,
- this,
- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
-
- std::set<vsomeip::eventgroup_t> its_groups;
- its_groups.insert(SAMPLE_EVENTGROUP_ID);
- app_->request_event(
- SAMPLE_SERVICE_ID,
- SAMPLE_INSTANCE_ID,
- SAMPLE_EVENT_ID,
- its_groups,
- true);
- app_->subscribe(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENTGROUP_ID);
-
- return true;
- }
-
- void start() {
- app_->start();
- }
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- /*
- * Handle signal to shutdown
- */
- void stop() {
- app_->clear_all_handler();
- app_->unsubscribe(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENTGROUP_ID);
- app_->release_event(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID);
- app_->release_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
- app_->stop();
- }
-#endif
-
- void on_state(vsomeip::state_type_e _state) {
- if (_state == vsomeip::state_type_e::ST_REGISTERED) {
- app_->request_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
- }
- }
-
- void on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
- std::cout << "Service ["
- << std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
- << "] is "
- << (_is_available ? "available." : "NOT available.")
- << std::endl;
- }
-
- void on_message(const std::shared_ptr<vsomeip::message> &_response) {
- std::stringstream its_message;
- its_message << "Received a notification for Event ["
- << std::setw(4) << std::setfill('0') << std::hex
- << _response->get_service() << "."
- << std::setw(4) << std::setfill('0') << std::hex
- << _response->get_instance() << "."
- << std::setw(4) << std::setfill('0') << std::hex
- << _response->get_method() << "] to Client/Session ["
- << std::setw(4) << std::setfill('0') << std::hex
- << _response->get_client() << "/"
- << std::setw(4) << std::setfill('0') << std::hex
- << _response->get_session()
- << "] = ";
- std::shared_ptr<vsomeip::payload> its_payload =
- _response->get_payload();
- its_message << "(" << std::dec << its_payload->get_length() << ") ";
- for (uint32_t i = 0; i < its_payload->get_length(); ++i)
- its_message << std::hex << std::setw(2) << std::setfill('0')
- << (int) its_payload->get_data()[i] << " ";
- std::cout << its_message.str() << std::endl;
-
- if (_response->get_client() == 0) {
- if ((its_payload->get_length() % 5) == 0) {
- std::shared_ptr<vsomeip::message> its_get
- = vsomeip::runtime::get()->create_request();
- its_get->set_service(SAMPLE_SERVICE_ID);
- its_get->set_instance(SAMPLE_INSTANCE_ID);
- its_get->set_method(SAMPLE_GET_METHOD_ID);
- its_get->set_reliable(use_tcp_);
- app_->send(its_get, true);
- }
-
- if ((its_payload->get_length() % 8) == 0) {
- std::shared_ptr<vsomeip::message> its_set
- = vsomeip::runtime::get()->create_request();
- its_set->set_service(SAMPLE_SERVICE_ID);
- its_set->set_instance(SAMPLE_INSTANCE_ID);
- its_set->set_method(SAMPLE_SET_METHOD_ID);
- its_set->set_reliable(use_tcp_);
-
- const vsomeip::byte_t its_data[]
- = { 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0x50, 0x51, 0x52 };
- std::shared_ptr<vsomeip::payload> its_set_payload
- = vsomeip::runtime::get()->create_payload();
- its_set_payload->set_data(its_data, sizeof(its_data));
- its_set->set_payload(its_set_payload);
- app_->send(its_set, true);
- }
- }
- }
-
-private:
- std::shared_ptr< vsomeip::application > app_;
- bool use_tcp_;
-};
-
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- client_sample *its_sample_ptr(nullptr);
- void handle_signal(int _signal) {
- if (its_sample_ptr != nullptr &&
- (_signal == SIGINT || _signal == SIGTERM))
- its_sample_ptr->stop();
- }
-#endif
-
-int main(int argc, char **argv) {
- bool use_tcp = false;
-
- std::string tcp_enable("--tcp");
- std::string udp_enable("--udp");
-
- int i = 1;
- while (i < argc) {
- if (tcp_enable == argv[i]) {
- use_tcp = true;
- } else if (udp_enable == argv[i]) {
- use_tcp = false;
- }
- i++;
- }
-
- client_sample its_sample(use_tcp);
-#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
- its_sample_ptr = &its_sample;
- signal(SIGINT, handle_signal);
- signal(SIGTERM, handle_signal);
-#endif
- if (its_sample.init()) {
- its_sample.start();
- return 0;
- } else {
- return 1;
- }
-}