diff options
author | Lutz Bichler <Lutz.Bichler@bmw.de> | 2014-10-20 12:31:21 +0200 |
---|---|---|
committer | Lutz Bichler <Lutz.Bichler@bmw.de> | 2014-10-20 12:31:21 +0200 |
commit | ba71072f464340e3c48819f8f208a68350dfbfa9 (patch) | |
tree | 3a518b448acb758702427bdd64b5d50d3d001cfd | |
parent | bb54baa1bbbabe3b36826efcc989b182e3fcaecd (diff) | |
download | vSomeIP-ba71072f464340e3c48819f8f208a68350dfbfa9.tar.gz |
Removed "get/set" methods in application interface. The removed
implementation used the event identifiers instead of the specific
identifiers for setters and getters.
As it is not possible to hide the specific get/set identifier from an
application without changing method/event identifiers, the
responsibility for implementing get/set is shifted to the application
layer.
Introduced a new interface function "notify", which can be used by an
application to update a local event with a given payload. This function
should be called whenever an event/field changes its value, thus it is
especially useful for implementing the set function.
Adapted the subscribe/notify sample to use the new interface.
Signed-off-by: Lutz Bichler <Lutz.Bichler@bmw.de>
-rw-r--r-- | examples/notify-sample.cpp | 48 | ||||
-rw-r--r-- | examples/sample-ids.hpp | 5 | ||||
-rw-r--r-- | examples/subscribe-sample.cpp | 23 | ||||
-rw-r--r-- | implementation/routing/include/routing_manager.hpp | 10 | ||||
-rw-r--r-- | implementation/routing/include/routing_manager_impl.hpp | 10 | ||||
-rw-r--r-- | implementation/routing/include/routing_manager_proxy.hpp | 10 | ||||
-rw-r--r-- | implementation/routing/src/routing_manager_impl.cpp | 83 | ||||
-rw-r--r-- | implementation/routing/src/routing_manager_proxy.cpp | 45 | ||||
-rw-r--r-- | implementation/runtime/include/application_impl.hpp | 5 | ||||
-rw-r--r-- | implementation/runtime/src/application_impl.cpp | 20 | ||||
-rw-r--r-- | interface/vsomeip/application.hpp | 10 |
11 files changed, 102 insertions, 167 deletions
diff --git a/examples/notify-sample.cpp b/examples/notify-sample.cpp index ccfea1d..484a7e8 100644 --- a/examples/notify-sample.cpp +++ b/examples/notify-sample.cpp @@ -33,6 +33,22 @@ public: std::bind(&service_sample::on_event, 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)); + + payload_ = vsomeip::runtime::get()->create_payload(); + blocked_ = true; condition_.notify_one(); } @@ -67,6 +83,24 @@ public: } } + void on_get(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, use_tcp_); + } + + void on_set(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, use_tcp_); + app_->notify(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, + SAMPLE_EVENT_ID, payload_); + } + void run() { std::unique_lock<std::mutex> its_lock(mutex_); while (!blocked_) @@ -85,8 +119,12 @@ public: } void notify() { - std::shared_ptr<vsomeip::payload> its_payload - = vsomeip::runtime::get()->create_payload(); + std::shared_ptr<vsomeip::message> its_message + = vsomeip::runtime::get()->create_request(); + + 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; @@ -102,10 +140,10 @@ public: for (uint32_t i = 0; i < its_size; ++i) its_data[i] = static_cast<uint8_t>(i); - its_payload->set_data(its_data, its_size); + payload_->set_data(its_data, its_size); VSOMEIP_INFO << "Setting event (Length=" << std::dec << its_size << ")."; - app_->set(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, its_payload, use_tcp_); + app_->notify(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, payload_); its_size++; @@ -129,6 +167,8 @@ private: std::mutex notify_mutex_; std::condition_variable notify_condition_; bool is_offered_; + + std::shared_ptr<vsomeip::payload> payload_; }; int main(int argc, char **argv) { diff --git a/examples/sample-ids.hpp b/examples/sample-ids.hpp index 45a6f85..f949ebd 100644 --- a/examples/sample-ids.hpp +++ b/examples/sample-ids.hpp @@ -10,7 +10,10 @@ #define SAMPLE_SERVICE_ID 0x1234 #define SAMPLE_INSTANCE_ID 0x5678 #define SAMPLE_METHOD_ID 0x8421 -#define SAMPLE_EVENT_ID 0x0778 + +#define SAMPLE_EVENT_ID 0x0778 +#define SAMPLE_GET_METHOD_ID 0x8001 +#define SAMPLE_SET_METHOD_ID 0x8002 #define SAMPLE_EVENTGROUP_ID 0x4465 diff --git a/examples/subscribe-sample.cpp b/examples/subscribe-sample.cpp index 15ebba7..acf9790 100644 --- a/examples/subscribe-sample.cpp +++ b/examples/subscribe-sample.cpp @@ -74,17 +74,30 @@ public: VSOMEIP_INFO << its_message.str(); if (_response->get_client() == 0) { - if ((its_payload->get_length() % 5) == 0) - app_->get(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, use_tcp_); + 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); + app_->send(its_get, true, use_tcp_); + } 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); + const vsomeip::byte_t its_data[] = { 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x50, 0x51, 0x52 }; - std::shared_ptr<vsomeip::payload> its_new_payload + std::shared_ptr<vsomeip::payload> its_set_payload = vsomeip::runtime::get()->create_payload(); - its_new_payload->set_data(its_data, sizeof(its_data)); - app_->set(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, its_new_payload, use_tcp_); + its_set_payload->set_data(its_data, sizeof(its_data)); + its_set->set_payload(its_set_payload); + app_->send(its_set, true, use_tcp_); } } } diff --git a/implementation/routing/include/routing_manager.hpp b/implementation/routing/include/routing_manager.hpp index b6dac3e..3416dc1 100644 --- a/implementation/routing/include/routing_manager.hpp +++ b/implementation/routing/include/routing_manager.hpp @@ -67,14 +67,8 @@ public: virtual bool send_to(const std::shared_ptr<endpoint_definition> &_target, const byte_t *_data, uint32_t _size) = 0; - virtual bool get(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, - bool _reliable) = 0; - - virtual bool set(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, - const std::shared_ptr<payload> &_value, - bool _reliable) = 0; + virtual void notify(service_t _service, instance_t _instance, event_t _event, + std::shared_ptr<payload> _payload) const = 0; virtual bool is_available(service_t _service, instance_t _instance) const = 0; diff --git a/implementation/routing/include/routing_manager_impl.hpp b/implementation/routing/include/routing_manager_impl.hpp index 4774367..ef715ce 100644 --- a/implementation/routing/include/routing_manager_impl.hpp +++ b/implementation/routing/include/routing_manager_impl.hpp @@ -94,14 +94,8 @@ public: bool send_to(const std::shared_ptr<endpoint_definition> &_target, const byte_t *_data, uint32_t _size); - bool get(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, - bool _reliable); - - bool set(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, - const std::shared_ptr<payload> &_payload, - bool _reliable); + void notify(service_t _service, instance_t _instance, event_t _event, + std::shared_ptr<payload> _payload) const; bool is_available(service_t _service, instance_t _instance) const; diff --git a/implementation/routing/include/routing_manager_proxy.hpp b/implementation/routing/include/routing_manager_proxy.hpp index 8819345..c73fd3d 100644 --- a/implementation/routing/include/routing_manager_proxy.hpp +++ b/implementation/routing/include/routing_manager_proxy.hpp @@ -70,14 +70,8 @@ public: bool send_to(const std::shared_ptr<endpoint_definition> &_target, const byte_t *_data, uint32_t _size); - bool get(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, - bool _reliable); - - bool set(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, - const std::shared_ptr<payload> &_value, - bool _reliable); + void notify(service_t _service, instance_t _instance, event_t _event, + std::shared_ptr<payload> _payload) const; void on_connect(std::shared_ptr<endpoint> _endpoint); void on_disconnect(std::shared_ptr<endpoint> _endpoint); diff --git a/implementation/routing/src/routing_manager_impl.cpp b/implementation/routing/src/routing_manager_impl.cpp index 2c0710e..0084dba 100644 --- a/implementation/routing/src/routing_manager_impl.cpp +++ b/implementation/routing/src/routing_manager_impl.cpp @@ -361,74 +361,6 @@ bool routing_manager_impl::send_local( return _target->send(&its_command[0], its_command.size(),_flush); } -bool routing_manager_impl::get(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, bool _reliable) { - bool is_sent(false); - std::shared_ptr<event> its_event = find_event(_service, _instance, _event); - if (its_event) { // local - // TODO: bring back the result to the application - } else { // remote - std::shared_ptr<endpoint> its_target = find_remote_client(_service, _instance, _reliable); - if (its_target) { - std::shared_ptr<message> its_request = runtime::get()->create_request(); - if (its_request) { - its_request->set_service(_service); - its_request->set_instance(_instance); - its_request->set_method(_event); - its_request->set_client(_client); - its_request->set_session(_session); - - std::unique_lock<std::mutex> its_lock(serialize_mutex_); - if (serializer_->serialize(its_request.get())) { - is_sent = its_target->send(serializer_->get_data(), serializer_->get_size()); - } else { - VSOMEIP_ERROR << "routing_manager_impl::get: serialization error."; - } - serializer_->reset(); - } - } else { - VSOMEIP_ERROR << "routing_manager_impl::get: cannot find endpoint for event."; - } - } - return (is_sent); -} - -bool routing_manager_impl::set(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, - const std::shared_ptr<payload> &_payload, bool _reliable) { - bool is_set(false); - std::shared_ptr<event> its_event = find_event(_service, _instance, _event); - if (its_event) { - its_event->set_payload(_payload); - // TODO: somehow bring back the result to the application as set according to SOME/IP is set+get - is_set = true; - } else { - std::shared_ptr<endpoint> its_target = find_remote_client(_service, _instance, _reliable); - if (its_target) { - std::shared_ptr<message> its_request = runtime::get()->create_request(); - if (its_request) { - its_request->set_service(_service); - its_request->set_instance(_instance); - its_request->set_method(_event); - its_request->set_client(_client); - its_request->set_session(_session); - its_request->set_payload(_payload); - - std::lock_guard<std::mutex> its_lock(serialize_mutex_); - if (serializer_->serialize(its_request.get())) { - is_set = its_target->send(serializer_->get_data(), serializer_->get_size()); - } else { - VSOMEIP_ERROR << "routing_manager_impl::set: serialization error."; - } - serializer_->reset(); - } - } else { - VSOMEIP_ERROR << "routing_manager_impl::set: cannot find endpoint for event."; - } - } - return (is_set); -} - bool routing_manager_impl::send_to( const std::shared_ptr<endpoint_definition> &_target, std::shared_ptr<message> _message) { @@ -453,9 +385,22 @@ bool routing_manager_impl::send_to( return (its_endpoint && its_endpoint->send_to(_target, _data, _size)); } +void routing_manager_impl::notify( + service_t _service, instance_t _instance, event_t _event, + std::shared_ptr<payload> _payload) const { + std::shared_ptr<event> its_event = find_event(_service, _instance, _event); + if (its_event) { + its_event->set_payload(_payload); + } else { + VSOMEIP_ERROR << "routing_manager_impl::notify: event [" + << std::hex << _service << "." << _instance << "." << _event + << "] is unknown."; + } +} + void routing_manager_impl::on_message(const byte_t *_data, length_t _size, endpoint *_receiver) { -#if 1 +#if 0 std::stringstream msg; msg << "rmi::on_message: "; for (uint32_t i = 0; i < _size; ++i) diff --git a/implementation/routing/src/routing_manager_proxy.cpp b/implementation/routing/src/routing_manager_proxy.cpp index 2419604..f498cf4 100644 --- a/implementation/routing/src/routing_manager_proxy.cpp +++ b/implementation/routing/src/routing_manager_proxy.cpp @@ -280,50 +280,17 @@ bool routing_manager_proxy::send_to( return (false); } -bool routing_manager_proxy::get(client_t _client, session_t _session, - service_t _service, instance_t _instance, event_t _event, bool _reliable) { - bool is_sent(false); - std::shared_ptr<event> its_event = find_event(_service, _instance, _event); - if (its_event) { // local - // TODO: bring back the result to the application - } else { // remote - std::shared_ptr<message> its_request = runtime::get()->create_request(); - if (its_request) { - its_request->set_service(_service); - its_request->set_instance(_instance); - its_request->set_method(_event); - its_request->set_client(_client); - its_request->set_session(_session); - - is_sent = send(_client, its_request, true, _reliable); - } - } - return (is_sent); -} - -bool routing_manager_proxy::set(client_t _client, session_t _session, +void routing_manager_proxy::notify( service_t _service, instance_t _instance, event_t _event, - const std::shared_ptr<payload> &_payload, bool _reliable) { - bool is_set(false); + std::shared_ptr<payload> _payload) const { std::shared_ptr<event> its_event = find_event(_service, _instance, _event); if (its_event) { its_event->set_payload(_payload); - // TODO: somehow bring back the result to the application as set according to SOME/IP is set+get - is_set = true; } else { - std::shared_ptr<message> its_request = runtime::get()->create_request(); - if (its_request) { - its_request->set_service(_service); - its_request->set_instance(_instance); - its_request->set_method(_event); - its_request->set_client(_client); - its_request->set_session(_session); - its_request->set_payload(_payload); - - is_set = send(_client, its_request, true, _reliable); - } + VSOMEIP_ERROR << "routing_manager_proxy::notify: event [" + << std::hex << _service << "." << _instance << "." << _event + << "] is unknown."; } - return (is_set); } void routing_manager_proxy::on_connect(std::shared_ptr<endpoint> _endpoint) { @@ -342,7 +309,7 @@ void routing_manager_proxy::on_disconnect(std::shared_ptr<endpoint> _endpoint) { void routing_manager_proxy::on_message(const byte_t *_data, length_t _size, endpoint *_receiver) { -#if 0 +#if 1 std::stringstream msg; msg << "rmp::on_message: "; for (int i = 0; i < _size; ++i) diff --git a/implementation/runtime/include/application_impl.hpp b/implementation/runtime/include/application_impl.hpp index aec8c5d..70c408d 100644 --- a/implementation/runtime/include/application_impl.hpp +++ b/implementation/runtime/include/application_impl.hpp @@ -54,9 +54,8 @@ public: void send(std::shared_ptr<message> _message, bool _flush, bool _reliable); - void get(service_t _service, instance_t, event_t _event, bool _reliable); - void set(service_t _service, instance_t _instance, event_t _event, - const std::shared_ptr<payload> &_payload, bool _reliable); + void notify(service_t _service, instance_t _instance, event_t _event, + std::shared_ptr<payload> _payload) const; void register_event_handler(event_handler_t _handler); void unregister_event_handler(); diff --git a/implementation/runtime/src/application_impl.cpp b/implementation/runtime/src/application_impl.cpp index 1416c36..a7c53b0 100644 --- a/implementation/runtime/src/application_impl.cpp +++ b/implementation/runtime/src/application_impl.cpp @@ -177,22 +177,10 @@ void application_impl::send(std::shared_ptr<message> _message, bool _flush, } } -void application_impl::get(service_t _service, instance_t _instance, event_t _event, - bool _reliable) { - if (routing_) { - if (routing_->get(client_, session_, _service, _instance, _event, _reliable)) { - update_session(); - } - } -} - -void application_impl::set(service_t _service, instance_t _instance, event_t _event, - const std::shared_ptr<payload> &_payload, bool _reliable) { - if (routing_) { - if (routing_->set(client_, session_, _service, _instance, _event, _payload, _reliable)) { - update_session(); - } - } +void application_impl::notify(service_t _service, instance_t _instance, event_t _event, + std::shared_ptr<payload> _payload) const { + if (routing_) + routing_->notify(_service, _instance, _event, _payload); } void application_impl::register_event_handler(event_handler_t _handler) { diff --git a/interface/vsomeip/application.hpp b/interface/vsomeip/application.hpp index 8a64fde..529b1c2 100644 --- a/interface/vsomeip/application.hpp +++ b/interface/vsomeip/application.hpp @@ -56,15 +56,13 @@ public: virtual bool is_available(service_t _service, instance_t _instance) = 0; - // Send messages + // Send a message virtual void send(std::shared_ptr<message> _message, bool _flush = true, bool _reliable = false) = 0; - // Set events/fields - virtual void get(service_t _service, instance_t _instance, - event_t _event, bool _reliable) = 0; - virtual void set(service_t _service, instance_t _instance, event_t _event, - const std::shared_ptr<payload> &_value, bool _reliable) = 0; + // Notify subscribers in case an event payload changes + virtual void notify(service_t _service, instance_t _instance, event_t _event, + std::shared_ptr<payload> _payload) const = 0; // Receive events (Non-SOME/IP) virtual void register_event_handler(event_handler_t _handler) = 0; |