From 2f0fdc596d24621c2bd4223cc63c8c1fb5b4c2d8 Mon Sep 17 00:00:00 2001 From: Juergen Gehring Date: Tue, 22 May 2018 02:56:40 -0700 Subject: vsomeip 2.10.11 --- interface/vsomeip/application.hpp | 954 +++++++++++++++++++++ interface/vsomeip/constants.hpp | 61 ++ interface/vsomeip/defines.hpp | 40 + interface/vsomeip/enumeration_types.hpp | 74 ++ interface/vsomeip/error.hpp | 26 + interface/vsomeip/export.hpp | 30 + interface/vsomeip/function_types.hpp | 22 + interface/vsomeip/handler.hpp | 33 + interface/vsomeip/internal/deserializable.hpp | 24 + interface/vsomeip/internal/serializable.hpp | 30 + interface/vsomeip/message.hpp | 52 ++ interface/vsomeip/message_base.hpp | 212 +++++ interface/vsomeip/payload.hpp | 106 +++ interface/vsomeip/plugin.hpp | 89 ++ interface/vsomeip/plugins/application_plugin.hpp | 42 + .../vsomeip/plugins/pre_configuration_plugin.hpp | 29 + interface/vsomeip/primitive_types.hpp | 49 ++ interface/vsomeip/runtime.hpp | 216 +++++ interface/vsomeip/vsomeip.hpp | 20 + 19 files changed, 2109 insertions(+) create mode 100644 interface/vsomeip/application.hpp create mode 100644 interface/vsomeip/constants.hpp create mode 100644 interface/vsomeip/defines.hpp create mode 100644 interface/vsomeip/enumeration_types.hpp create mode 100644 interface/vsomeip/error.hpp create mode 100644 interface/vsomeip/export.hpp create mode 100644 interface/vsomeip/function_types.hpp create mode 100644 interface/vsomeip/handler.hpp create mode 100644 interface/vsomeip/internal/deserializable.hpp create mode 100644 interface/vsomeip/internal/serializable.hpp create mode 100644 interface/vsomeip/message.hpp create mode 100644 interface/vsomeip/message_base.hpp create mode 100644 interface/vsomeip/payload.hpp create mode 100644 interface/vsomeip/plugin.hpp create mode 100644 interface/vsomeip/plugins/application_plugin.hpp create mode 100644 interface/vsomeip/plugins/pre_configuration_plugin.hpp create mode 100644 interface/vsomeip/primitive_types.hpp create mode 100644 interface/vsomeip/runtime.hpp create mode 100644 interface/vsomeip/vsomeip.hpp (limited to 'interface') diff --git a/interface/vsomeip/application.hpp b/interface/vsomeip/application.hpp new file mode 100644 index 0000000..42bd534 --- /dev/null +++ b/interface/vsomeip/application.hpp @@ -0,0 +1,954 @@ +// 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_APPLICATION_HPP +#define VSOMEIP_APPLICATION_HPP + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace vsomeip { + +class configuration; +class event; +class payload; + +/** + * \defgroup vsomeip + * + * @{ + */ + +/** + * + * \brief This class contains the public API of the vsomeip implementation. + * + * Due to its heavy resource footprint, it should exist once per client and can + * be instantiated using the API of @ref runtime. It manages the lifecycle of + * the vsomeip client and allocates all resources needed to communicate. + * + */ +class application { +public: + virtual ~application() {} + + /** + * + * \brief Returns the name of the application as given during creation + * + * The application name is used to identify the application. It is either + * set explicitely when the application object is created or configured by + * the environment variable VSOMEIP_APPLICATION_NAME. + * + * Note: A user application can use several vsomeip application objects in + * parallel. The application names must be set explicitly in this case + * because VSOMEIP_APPLICATION_NAME only allows to specify a single name. + * + * + * \return Application name + * + */ + virtual const std::string & get_name() const = 0; + + /** + * + * \brief Returns the client identifier that was assigned to the + * application object. + * + * Each request sent by and each response sent to the application contain + * the client identifier as part of the request identifier within the + * SOME/IP message header. The client identifier can either be configured + * by the configured as part of the application node within a vsomeip + * configuration file or is automatically set to an unused client + * identifier by vsomeip. If the client identifier is automatically set, + * its high byte will always match the diagnosis address of the device. + * + * \return Client ID of application + * + */ + virtual client_t get_client() const = 0; + + /** + * + * \brief Does nothing. + * + * This method exists for compatibility reasons only. It is a null + * operation and will be removed with the next major vsomeip version. + * + */ + virtual void set_configuration(const std::shared_ptr _configuration) = 0; + + /** + * + * \brief Initializes the application. + * + * The init method must be called first after creating a vsomeip + * application and executes the following steps to initialize it: + * - Loading the configuration from a dynamic module + * - Loading the configuration from a .json file or + * - Loading the configuration from compiled data (not yet available) + * - Determining routing configuration and initialization of the routing + * itself + * - Installing signal handlers + * + */ + virtual bool init() = 0; + + /** + * + * \brief Starts message processing. + * + * This method must be called after init to start message processing. It + * will block until the message processing is terminated using the @ref + * stop method or by receiving signals. It processes messages received + * via the sockets and uses registered callbacks to pass them to the user + * application. + * + */ + virtual void start() = 0; + + /** + * + * \brief Stops message processing. + * + * This method stops message processing. Thus, @ref start will return + * after a call to stop. + * + */ + virtual void stop() = 0; + + /** + * + * \brief Offers a SOME/IP service instance. + * + * The user application must call this method for each service it offers + * to register it at the vsomeip routing component, which makes the + * service visible to interested clients. Dependent on the configuration + * the service is available internally only or internally and externally. + * To offer a service to the external network, the configuration must + * contain a port for the offered service instance. If no such port + * configuration is provided, the service is not visible outside the + * device. + * + * \param _service Service identifier of the offered service interface. + * \param _instance Instance identifier of the offered service instance. + * \param _major Major service version (Default: 0). + * \param _minor Minor service version (Default: 0). + * + */ + virtual void offer_service(service_t _service, instance_t _instance, + major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor = + DEFAULT_MINOR) = 0; + + /** + * + * \brief Stops offering a SOME/IP service instance. + * + * The user application must call this method to withdraw a service offer. + * + * \param _service Service identifier of the offered service interface. + * \param _instance Instance identifer of the offered service instance. + * \param _major Major service version (Default: 0). + * \param _minor Minor service version (Default: 0). + * + */ + virtual void stop_offer_service(service_t _service, instance_t _instance, + major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor = + DEFAULT_MINOR) = 0; + + /** + * + * \brief Offers a SOME/IP event or field. + * + * A user application must call this method for each event/field it wants + * to offer. The event is registered at the vsomeip routing component that + * enables other applications to subscribe to the event/field as well as + * to get and set the field value. + * + * \param _service Service identifier of the interface containing the + * event. + * \param _instance Instance identifier of the interface containing the + * event. + * \param _event Event identifier of the offered event. + * \param _eventgroups List of eventgroup identifiers of the eventgroups + * that contain the event. + * \param _is_field Selector for event or field. + * + */ + virtual void offer_event(service_t _service, + instance_t _instance, event_t _event, + const std::set &_eventgroups, + bool _is_field) = 0; + + /** + * + * \brief Stops offering a SOME/IP event or field. + * + * A user application must call this method to withdraw the offer of an + * event or field. + * + * \param _service Service identifier of the interface that contains the + * event + * \param _instance Instance identifier of the interface that contains the + * event + * \param _event Event identifier of the offered event. + * + */ + virtual void stop_offer_event(service_t _service, + instance_t _instance, event_t _event) = 0; + + /** + * + * \brief Registers the application as client of a service instance. + * + * A user application must call this method for each service instance it + * wants to use. The request is stored within the routing component and the + * application is registered as client for the service as soon as the + * service instance becomes available. + * + * \param _service Service identifier of the requested service interface. + * \param _instance Instance identifier of the requested service instance. + * \param _major Major service version (Default: 0xFF). + * \param _minor Minor service version (Default: 0xFFFFFF). + * \param _use_exclusive_proxy Create an IP endpoint that is exclusively + * used for the communication of this application to the service instance. + * + */ + virtual void request_service(service_t _service, instance_t _instance, + major_version_t _major = ANY_MAJOR, + minor_version_t _minor = ANY_MINOR, + bool _use_exclusive_proxy = false) = 0; + + /** + * + * \brief Unregister the application as client of a service instance. + * + * A user application should call this method if it does not request to + * use the service instance any longer. The method unregisters the request + * a the routing component, which removes the service instance from the + * list of requested service instances if the call releases the last + * existing request for the service instance. This is important for + * external service instances, as the SOME/IP Service Discovery can avoid + * to send unnecessary Find messages. + * + * \param _service Service identifier of the offered service interface. + * \param _instance Instance identifier of the offered service instance. + * + */ + virtual void release_service(service_t _service, instance_t _instance) = 0; + + /** + * + * \brief Registers the application as user of an event or field. + * + * A user application must call this method before being able to receive + * event or field data. The method registers the event or field at the + * routing component. + * + * \param _service Service identifier of the interface that contains the + * event. + * \param _instance Instance identifier of the interface that contains the + * event. + * \param _event Event identifier of the event. + * \param _eventgroups List of Eventgroup identifiers of the eventgroups + * that contain the event. + * \param _is_field Pure event (false) or field (true). + * + */ + virtual void request_event(service_t _service, instance_t _instance, + event_t _event, const std::set &_eventgroups, + bool _is_field) = 0; + /** + * + * \brief Unregister the application as user of an event or field. + * + * Unregister the application as user of an event or field and completely + * removes the event/field if the application is the last existing user. + * + * \param _service Service identifier of the interface that contains the + * event or field. + * \param _instance Instance identifier of the instance that contains the + * event or field. + * \param _event Event identifier of the event or field. + * . + */ + virtual void release_event(service_t _service, instance_t _instance, + event_t _event) = 0; + + /** + * + * \brief Subscribes to an eventgroup. + * + * A user application must call this function to subscribe to an eventgroup. + * Before calling subscribe it must register all events it interested in by + * calls to @ref request_event. The method additionally allows to specify + * a specific event. If a specific event is specified, all other events of + * the eventgroup are not received by the application. + * + * Note: For external services, providing a specific event does not change + * anything regarding the message routing. The specific event is only used + * to filter incoming events and to determine which initial events must be + * sent. + * + * \param _service Service identifier of the service that contains the + * eventgroup. + * \param _instance Instance identifier of the service that contains the + * eventgroup. + * \param _eventgroup Eventgroup identifier of the eventgroup. + * \param _major Major version number of the service. + * \param _subscription_type Specifies how the events shall be received. + * \param _event All (Default) or a specific event. + * + */ + virtual void subscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup, major_version_t _major = DEFAULT_MAJOR, + subscription_type_e _subscription_type = subscription_type_e::SU_RELIABLE_AND_UNRELIABLE, + event_t _event = ANY_EVENT) = 0; + + /** + * + * \brief Unsubscribes from an eventgroup. + * + * \param _service Service identifier of the service that contains the + * eventgroup. + * \param _instance Instance identifier of the service that contains the + * eventgroup. + * \param _eventgroup Eventgroup identifier of the eventgroup. + * + */ + virtual void unsubscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup) = 0; + + /** + * + * \brief Retrieve for the availability of a service instance. + * + * If the version is also given, the result will only be true if the + * service instance is available in that specific version. + * + * \param _service Service identifier of the service instance. + * \param _instance Instance identifier of the service instance. + * \param _major Major interface version. Use ANY_MAJOR to ignore the + * major version. + * \param _minor Minor interface version. Use ANY_MINOR to ignore the + * minor version. + * + */ + virtual bool is_available(service_t _service, instance_t _instance, + major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor = DEFAULT_MINOR) const = 0; + + /** + * + * \brief Sends a message. + * + * Serializes the specified message object, determines the taget and sends + * the message to the target. For requests, the request identifier is + * automatically built from the client identifier and the session + * identifier. + * + * \param _message Message object. + * \param _flush If set to true, the message is immediately sent. Otherwise + * the message might be deferred and sent together with other messages. + * + */ + virtual void send(std::shared_ptr _message, bool _flush = true) = 0; + + /** + * + * \brief Fire an event or field notification. + * + * The specified event is updated with the specified payload data. + * Dependent on the type of the event, the payload is distributed to all + * notified clients (always for events, only if the payload has changed + * for fields). + * + * Note: Prior to using this method, @ref offer_event has to be called by + * the service provider. + * + * \param _service Service identifier of the service that contains the + * event. + * \param _instance Instance identifier of the service instance that + * holds the event. + * \param _event Event identifier of the event. + * \param _payload Serialized payload of the event. + * + */ + virtual void notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr _payload) const = 0; + + /** + * + * \brief Fire an event to a specific client. + * + * The specified event is updated with the specified payload data. + * Dependent on the type of the event, the payload is distributed to all + * notified clients (always for events, only if the payload has changed + * for fields). + * + * Note: Prior to using this method, @ref offer_event has to be called by + * the service provider. + * + * \param _service Service identifier of the service that contains the + * event. + * \param _instance Instance identifier of the service instance that + * holds the event. + * \param _event Event identifier of the event. + * \param _payload Serialized payload of the event. + * \param _client Target client. + * + */ + virtual void notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr _payload, + client_t _client) const = 0; + + /** + * + * \brief Register a state handler with the vsomeip runtime. + * + * The state handler tells if this client is successfully [de]registered + * at the central vsomeip routing component. This is called during the + * @ref start and @ref stop methods of this class to inform the user + * application about the registration state. + * + * \param _handler Handler function to be called on state change. + * + */ + virtual void register_state_handler(state_handler_t _handler) = 0; + + /** + * + * \brief Unregister the state handler. + * + */ + virtual void unregister_state_handler() = 0; + + /** + * + * \brief Registers a handler for the specified method or event. + * + * A user application must call this method to register callbacks for + * for messages that match the specified service, instance, method/event + * pattern. It is possible to specify wildcard values for all three + * identifiers arguments. + * + * Notes: + * - Only a single handler can be registered per service, instance, + * method/event combination. + * - A subsequent call will overwrite an existing registration. + * - Handler registrations containing wildcards can be active in parallel + * to handler registrations for specific service, instance, method/event + * combinations. + * + * \param _service Service identifier of the service that contains the + * method or event. Can be set to ANY_SERVICE to register a handler for + * a message independent from a specific service. + * \param _instance Instance identifier of the service instance that + * contains the method or event. Can be set to ANY_INSTANCE to register + * a handler for a message independent from a specific service. + * \param _method Method/Event identifier of the method/event that is + * to be handled. Can be set to ANY_METHOD to register a handler for + * all methods and events. + * \param _handler Callback that will be called if a message arrives + * that matches the specified service, instance and method/event + * parameters. + * + */ + virtual void register_message_handler(service_t _service, + instance_t _instance, method_t _method, + message_handler_t _handler) = 0; + /** + * + * \brief Unregisters the message handler for the specified service + * method/event notification. + * + * \param _service Service identifier of the service that contains the + * method or event. Can be set to ANY_SERVICE to unregister a handler for + * a message independent from a specific service. + * \param _instance Instance identifier of the service instance that + * contains the method or event. Can be set to ANY_INSTANCE to unregister + * a handler for a message independent from a specific service. + * \param _method Method/Event identifier of the method/event that is + * to be handled. Can be set to ANY_METHOD to unregister a handler for + * all methods and events. + */ + virtual void unregister_message_handler(service_t _service, + instance_t _instance, method_t _method) = 0; + + /** + * + * \brief Register a callback that is called when service instances + * availability changes. + * + * This method allows for the registration of callbacks that are called + * whenever a service appears or disappears. It is possible to specify + * wildcards for service, instance and/or version. Additionally, the + * version specification is optional and defaults to DEFAULT_MAJOR + * /DEFAULT_MINOR. + * + * \param _service Service identifier of the service instance whose + * availability shall be reported. Can be set to ANY_SERVICE. + * \param _instance Instance identifier of the service instance whose + * availability shall be reported. Can be set to ANY_INSTANCE. + * \param _handler Callback to be called if availability changes. + * \param _major Major service version. The parameter defaults to + * DEFAULT_MAJOR and can be set to ANY_MAJOR. + * \param _minor Minor service version. The parameter defaults to + * DEFAULT_MINOR and can be set to ANY_MINOR. + * + */ + virtual void register_availability_handler(service_t _service, + instance_t _instance, availability_handler_t _handler, + major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor = DEFAULT_MINOR) = 0; + + /** + * + * \brief Unregister an availability callback. + * + * \param _service Service identifier of the service instance whose + * availability shall be reported. Can be set to ANY_SERVICE. + * \param _instance Instance identifier of the service instance whose + * availability shall be reported. Can be set to ANY_INSTANCE. + * \param _handler Callback to be called if availability changes. + * \param _major Major service version. The parameter defaults to + * DEFAULT_MAJOR and can be set to ANY_MAJOR. + * \param _minor Minor service version. The parameter defaults to + * DEFAULT_MINOR and can be set to ANY_MINOR. * + */ + virtual void unregister_availability_handler(service_t _service, + instance_t _instance, + major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor = DEFAULT_MINOR) = 0; + + /** + * + * \brief Registers a subscription handler. + * + * A subscription handler is called whenever the subscription state of an + * eventgroup changes. The callback is called with the client identifier + * and a boolean that indicates whether the client subscribed or + * unsubscribed. + * + * \param _service Service identifier of service instance whose + * subscription state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription state is to be monitored. + * \param _handler Callback that shall be called. + * + */ + virtual void register_subscription_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, + subscription_handler_t _handler) = 0; + + /** + * + * \brief Unregister a subscription handler. + * + * \param _service Service identifier of service instance whose + * subscription state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription state is to be monitored. + * + */ + virtual void unregister_subscription_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup) = 0; + + // [Un]Register handler for subscription errors + /** + * + * \brief Allows for the registration of a subscription error handler. + * + * This handler is called whenever a subscription request for an eventgroup + * was either accepted or rejected. The respective callback is called with + * ether OK (0x00) or REJECTED (0x07). + * + * \param _service Service identifier of service instance whose + * subscription error state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription error state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription error state is to be monitored. + * \param _handler Callback that shall be called. + * + */ + virtual void register_subscription_error_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, + error_handler_t _handler) = 0; + + /** + * + * \brief Removes a registered subscription error callback. + * + * \param _service Service identifier of service instance whose + * error callback shall be removed. + * \param _instance Instance identifier of service instance whose + * error callback shall be removed. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * error callback shall be removed. + * + */ + virtual void unregister_subscription_error_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup) = 0; + + /** + * + * \brief Unregister all registered handlers. + * + */ + virtual void clear_all_handler() = 0; + + /** + * + * \brief This method tells whether or not this application controls the + * message routing. + * + * The application that controls the routing hosts the routing manager + * and (optionally) loads the Service Discovery component. + * + * \return true, if this is the central routing instance, and false + * otherwise + * + */ + virtual bool is_routing() const = 0; + + /** + * + * \brief Offers a SOME/IP event or field. + * + * A user application must call this method for each event/field it wants + * to offer. The event is registered at the vsomeip routing component that + * enables other applications to subscribe to the event/field as well as + * to get and set the field value. + * + * This version of offer_event adds some additional functionalities: + * - It is possible to configure a cycle time. The notification message of + * this event is then resent cyclically. + * - The parameter _change_resets_cycle is available to control how event + * notification works in case the data is updated by the application. If + * set to true, an update of the data immediately leads to a + * notification. Otherwise, the updated data is sent only after the + * expiration of the cycle time. + * - It is possible to specify callback function that can be used to + * implement a predicate that determines whether or not two event values + * are considered different. Field notifications are only sent if the + * predicate evaluates to true (or if a notify method is called with the + * force flag being set). + * + * \param _service Service identifier of the interface containing the + * event. + * \param _instance Instance identifier of the interface containing the + * event. + * \param _event Event identifier of the offered event. + * \param _eventgroups List of eventgroup identifiers of the eventgroups + * that contain the event. + * \param _is_field Selector for event or field. + * \param _cycle Sets the cycle time of the event. If nonzero, data is + * resent cyclically after the cycle time expired. + * \param _change_resets_cycle Tells if a change immediately leads to + * a notification. + * \param _epsilon_change_func Predicate that determines if two given + * payloads are considered different. + * + * Note: The different versions of offer_event exist for compatibility + * reasons. They will be merged with the next major vsomeip version. + */ + virtual void offer_event(service_t _service, + instance_t _instance, event_t _event, + const std::set &_eventgroups, + bool _is_field, + std::chrono::milliseconds _cycle, + bool _change_resets_cycle, + const epsilon_change_func_t &_epsilon_change_func) = 0; + + /** + * + * \brief Fire an event or field notification. + * + * The specified event is updated with the specified payload data. + * Dependent on the type of the event, the payload is distributed to all + * notified clients (always for events, only if the payload has changed + * for fields). + * + * Note: Prior to using this method, @ref offer_event has to be called by + * the service provider. + * + * \param _service Service identifier of the service that contains the + * event. + * \param _instance Instance identifier of the service instance that + * holds the event. + * \param _event Event identifier of the event. + * \param _payload Serialized payload of the event. + * \param _force Forces the notification to be sent (even if the event + * is a field and the value did not change). + * + * Note: The different versions of notify do exist for compatibility + * reasons. They will be merged with the next major vsomeip release. + */ + virtual void notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr _payload, + bool _force) const = 0; + + /** + * + * \brief Fire an event or field notification. + * + * The specified event is updated with the specified payload data. + * Dependent on the type of the event, the payload is distributed to all + * notified clients (always for events, only if the payload has changed + * for fields). + * + * Note: Prior to using this method, @ref offer_event has to be called by + * the service provider. + * + * \param _service Service identifier of the service that contains the + * event. + * \param _instance Instance identifier of the service instance that + * holds the event. + * \param _event Event identifier of the event. + * \param _payload Serialized payload of the event. + * \param _client Target client. + * \param _force Forces the notification to be sent (even if the event + * is a field and the value did not change). + * + * Note: The different versions of notify_one do exist for compatibility + * reasons. They will be merged with the next major vsomeip release. + */ + virtual void notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr _payload, + client_t _client, bool _force) const = 0; + + typedef std::map>> available_t; + /** + * \brief Returns all available instances that match the given combination + * of service, instance and version. + * + * This method checks the availability of the service instances that + * match the specified combination of service, instance and version + * parameters. If at least one matching service instance is available, + * the method returns true, otherwise it returns false. All available + * service instances are returned to the caller by filling the + * _available parameter. + * + * \param _available Map that is filled with the available instances. + * \param _service Service identifier that specifies which service(s) + * are checked. + * \param _instance Instance identifier that specifies which instance(s) + * are checked. + * \param _major_version Major version(s) of the service instances that + * are checked + * \param _minor_version Minor version(s) of the service instance that + * are checked + */ + virtual bool are_available(available_t &_available, + service_t _service = ANY_SERVICE, instance_t _instance = ANY_INSTANCE, + major_version_t _major = ANY_MAJOR, minor_version_t _minor = ANY_MINOR) const = 0; + + /** + * + * \brief Fire an event or field notification. + * + * The specified event is updated with the specified payload data. + * Dependent on the type of the event, the payload is distributed to all + * notified clients (always for events, only if the payload has changed + * for fields). + * + * Note: Prior to using this method, @ref offer_event has to be called by + * the service provider. + * + * \param _service Service identifier of the service that contains the + * event. + * \param _instance Instance identifier of the service instance that + * holds the event. + * \param _event Event identifier of the event. + * \param _payload Serialized payload of the event. + * \param _force Forces the notification to be sent (even if the event + * is a field and the value did not change). + * \param _flush Must be set to ensure the event is immediately fired. + * + * Note: The different versions of notify do exist for compatibility + * reasons. They will be merged with the next major vsomeip release. + */ + virtual void notify(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr _payload, + bool _force, bool _flush) const = 0; + + /** + * + * \brief Fire an event or field notification. + * + * The specified event is updated with the specified payload data. + * Dependent on the type of the event, the payload is distributed to all + * notified clients (always for events, only if the payload has changed + * for fields). + * + * Note: Prior to using this method, @ref offer_event has to be called by + * the service provider. + * + * \param _service Service identifier of the service that contains the + * event. + * \param _instance Instance identifier of the service instance that + * holds the event. + * \param _event Event identifier of the event. + * \param _payload Serialized payload of the event. + * \param _client Target client. + * \param _force Forces the notification to be sent (even if the event + * is a field and the value did not change). + * \param _flush Must be set to ensure the event is immediately fired. + * + * Note: The different versions of notify_one do exist for compatibility + * reasons. They will be merged with the next major vsomeip release. + */ + virtual void notify_one(service_t _service, instance_t _instance, + event_t _event, std::shared_ptr _payload, + client_t _client, bool _force, bool _flush) const = 0; + + /** + * \brief Set the current routing state. + * + * The routing state impacts the behavior of the SOME/IP Service Discovery component. It + * can be set to RUNNING, SUSPENDED, RESUMED, SHUTDOWN or UNKNOWN. Applications only need + * to set the routing state if they are responsible for controlling the routing manager. + * In most environments the vsomeip daemon is controlling the routing manager. + * + * \param _routing_state the current routing state + */ + virtual void set_routing_state(routing_state_e _routing_state) = 0; + + /** + * + * \brief Unsubscribes from an eventgroup. + * + * \param _service Service identifier of the service that contains the + * eventgroup. + * \param _instance Instance identifier of the service that contains the + * eventgroup. + * \param _eventgroup Eventgroup identifier of the eventgroup. + * \param _event Event to unsubscribe (pass ANY_EVENT for all events of the eventgroup) + */ + virtual void unsubscribe(service_t _service, instance_t _instance, + eventgroup_t _eventgroup, event_t _event) = 0; + + + /** + * + * \brief Registers a subscription status listener. + * + * When registered such a handler it will be called for + * every application::subscribe call. + * + * This method is intended to replace the application:: + * register_subscription_error_handler call in future releases. + * + * \param _service Service identifier of the service that is subscribed to. + * \param _instance Instance identifier of the service that is subscribed to. + * \param _eventgroup Eventgroup identifier of the eventgroup is subscribed to. + * \param _event Event indentifier of the event is subscribed to. + * \param _handler A subscription status handler which will be called by vSomeIP + * as a follow of application::subscribe. + */ + virtual void register_subscription_status_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, event_t _event, + subscription_status_handler_t _handler) = 0; + + /** + * + * \brief Registers a subscription status listener. + * + * When registered such a handler it will be called for + * every application::subscribe call. + * + * This method is intended to replace the application:: + * register_subscription_error_handler call in future releases. + * + * \param _service Service identifier of the service that is subscribed to. + * \param _instance Instance identifier of the service that is subscribed to. + * \param _eventgroup Eventgroup identifier of the eventgroup is subscribed to. + * \param _event Event indentifier of the event is subscribed to. + * \param _handler A subscription status handler which will be called by vSomeIP + * as a follow of application::subscribe. + * \param _is_selective Flag to enable calling the provided handler if the + * subscription is answered with a SUBSCRIBE_NACK. + */ + virtual void register_subscription_status_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, event_t _event, + subscription_status_handler_t _handler, bool _is_selective) = 0; + + /** + * + * \brief Returns all registered services / instances on this node in an async callback. + * + * When called with a handler of type offered_services_handler_t, + * all at the routing manager registered services on this node get returned in a vector of + * service / instance pairs depending on the given _offer_type. + * + * \param _offer_type type of offered services to be returned (OT_LOCAL = 0x00, OT_REMOTE = 0x01, OT_ALL = 0x02) + * \param offered_services_handler_t handler which gets called with a vector of service instance pairs that are currently offered + */ + virtual void get_offered_services_async(offer_type_e _offer_type, offered_services_handler_t _handler) = 0; + + /** + * + * \brief Sets a handler to be called cyclically for watchdog monitoring. + * + * The handler shall be called in the given interval, but not before start() + * has been called, and not after call to stop() returned. + * + * In case the application is running, i.e. start() succeeded, but the + * handler will not be invoke within the (approximate) interval it may + * be assumed that I/O or internal dispatcher threads are non-functional. + * + * \remark Accuracy of call interval is limited by clock/timer granularity + * or scheduling effects, thus it may underrun or overrun by small + * amount. + * + * \note Only one handler can be active at the time, thus last handler set + * by calling this function will be invoked. + * + * \note To disable calling an active handler, invoke this method again, + * passing nullptr as _handler and/or std::chrono::seconds::zero() + * as _interval. + * + * \param _handler A watchdog handler, pass nullptr to deactivate. + * \param _interval Call interval in seconds, pass std::chrono::seconds::zero() to deactivate. + */ + virtual void set_watchdog_handler(watchdog_handler_t _handler, std::chrono::seconds _interval) = 0; + + /** + * + * \brief Registers a subscription handler. + * + * A subscription handler is called whenever the subscription state of an + * eventgroup changes. The callback is called with the client identifier + * and a boolean that indicates whether the client subscribed or + * unsubscribed. + * + * \param _service Service identifier of service instance whose + * subscription state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription state is to be monitored. + * \param _handler Callback that shall be called. + * + */ + virtual void register_async_subscription_handler(service_t _service, instance_t _instance, eventgroup_t _eventgroup, async_subscription_handler_t _handler) = 0; +}; + +/** @} */ + +} // namespace vsomeip + +#endif // VSOMEIP_APPLICATION_HPP diff --git a/interface/vsomeip/constants.hpp b/interface/vsomeip/constants.hpp new file mode 100644 index 0000000..d45f2c1 --- /dev/null +++ b/interface/vsomeip/constants.hpp @@ -0,0 +1,61 @@ +// 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_CONSTANTS_HPP +#define VSOMEIP_CONSTANTS_HPP + +#include + +#include +#include + +namespace vsomeip { + +const major_version_t DEFAULT_MAJOR = 0x00; +const minor_version_t DEFAULT_MINOR = 0x00000000; +const ttl_t DEFAULT_TTL = 0xFFFFFF; // "until next reboot" + +const std::string DEFAULT_MULTICAST = "224.0.0.0"; +const uint16_t DEFAULT_PORT = 30500; +const uint16_t ILLEGAL_PORT = 0xFFFF; + +const uint16_t NO_TRACE_FILTER_EXPRESSION = 0x0000; + +const service_t ANY_SERVICE = 0xFFFF; +const instance_t ANY_INSTANCE = 0xFFFF; +const method_t ANY_METHOD = 0xFFFF; +const major_version_t ANY_MAJOR = 0xFF; +const minor_version_t ANY_MINOR = 0xFFFFFFFF; + +const eventgroup_t DEFAULT_EVENTGROUP = 0x0001; + +const client_t ILLEGAL_CLIENT = 0x0000; + +const byte_t MAGIC_COOKIE_CLIENT_MESSAGE = 0x00; +const byte_t MAGIC_COOKIE_SERVICE_MESSAGE = 0x80; +const length_t MAGIC_COOKIE_SIZE = 0x00000008; +const request_t MAGIC_COOKIE_REQUEST = 0xDEADBEEF; +const protocol_version_t MAGIC_COOKIE_PROTOCOL_VERSION = 0x01; +const interface_version_t MAGIC_COOKIE_INTERFACE_VERSION = 0x01; +const message_type_e MAGIC_COOKIE_CLIENT_MESSAGE_TYPE = + message_type_e::MT_REQUEST_NO_RETURN; +const message_type_e MAGIC_COOKIE_SERVICE_MESSAGE_TYPE = + message_type_e::MT_NOTIFICATION; +const return_code_e MAGIC_COOKIE_RETURN_CODE = return_code_e::E_OK; + +const byte_t CLIENT_COOKIE[] = { 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x01, 0x01, 0x00 }; + +const byte_t SERVICE_COOKIE[] = { 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x08, 0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x01, 0x02, 0x00 }; + +const event_t ANY_EVENT = 0xFFFF; +const client_t ANY_CLIENT = 0xFFFF; + +const pending_subscription_id_t DEFAULT_SUBSCRIPTION = 0x0; + +} // namespace vsomeip + +#endif // VSOMEIP_CONSTANTS_HPP diff --git a/interface/vsomeip/defines.hpp b/interface/vsomeip/defines.hpp new file mode 100644 index 0000000..2a6af8b --- /dev/null +++ b/interface/vsomeip/defines.hpp @@ -0,0 +1,40 @@ +// 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_DEFINES_HPP +#define VSOMEIP_DEFINES_HPP + +#define VSOMEIP_PROTOCOL_VERSION 0x1 + +// 0 = unlimited, if not specified otherwise via configuration file +#define VSOMEIP_MAX_LOCAL_MESSAGE_SIZE 0 +// 0 = unlimited, if not specified otherwise via configuration file +#define VSOMEIP_MAX_TCP_MESSAGE_SIZE 0 +#define VSOMEIP_MAX_UDP_MESSAGE_SIZE 1416 + +#define VSOMEIP_PACKET_SIZE VSOMEIP_MAX_UDP_MESSAGE_SIZE + +#define VSOMEIP_SOMEIP_HEADER_SIZE 8 +#define VSOMEIP_SOMEIP_MAGIC_COOKIE_SIZE 8 + +#define VSOMEIP_SERVICE_POS_MIN 0 +#define VSOMEIP_SERVICE_POS_MAX 1 +#define VSOMEIP_METHOD_POS_MIN 2 +#define VSOMEIP_METHOD_POS_MAX 3 +#define VSOMEIP_EVENT_POS_MIN 2 +#define VSOMEIP_EVENT_POS_MAX 3 +#define VSOMEIP_LENGTH_POS_MIN 4 +#define VSOMEIP_LENGTH_POS_MAX 7 +#define VSOMEIP_CLIENT_POS_MIN 8 +#define VSOMEIP_CLIENT_POS_MAX 9 +#define VSOMEIP_SESSION_POS_MIN 10 +#define VSOMEIP_SESSION_POS_MAX 11 +#define VSOMEIP_PROTOCOL_VERSION_POS 12 +#define VSOMEIP_INTERFACE_VERSION_POS 13 +#define VSOMEIP_MESSAGE_TYPE_POS 14 +#define VSOMEIP_RETURN_CODE_POS 15 +#define VSOMEIP_PAYLOAD_POS 16 + +#endif // VSOMEIP_DEFINES_HPP diff --git a/interface/vsomeip/enumeration_types.hpp b/interface/vsomeip/enumeration_types.hpp new file mode 100644 index 0000000..1f83b81 --- /dev/null +++ b/interface/vsomeip/enumeration_types.hpp @@ -0,0 +1,74 @@ +// 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_ENUMERATION_TYPES_HPP +#define VSOMEIP_ENUMERATION_TYPES_HPP + +#include + +namespace vsomeip { + +enum class state_type_e : uint8_t { + ST_REGISTERED = 0x0, + ST_DEREGISTERED = 0x1 +}; + +// SIP_RPC_684 +enum class message_type_e : uint8_t { + MT_REQUEST = 0x00, + MT_REQUEST_NO_RETURN = 0x01, + MT_NOTIFICATION = 0x02, + MT_REQUEST_ACK = 0x40, + MT_REQUEST_NO_RETURN_ACK = 0x41, + MT_NOTIFICATION_ACK = 0x42, + MT_RESPONSE = 0x80, + MT_ERROR = 0x81, + MT_RESPONSE_ACK = 0xC0, + MT_ERROR_ACK = 0xC1, + MT_UNKNOWN = 0xFF +}; + +// SIP_RPC_371 +enum class return_code_e : uint8_t { + E_OK = 0x00, + E_NOT_OK = 0x01, + E_UNKNOWN_SERVICE = 0x02, + E_UNKNOWN_METHOD = 0x03, + E_NOT_READY = 0x04, + E_NOT_REACHABLE = 0x05, + E_TIMEOUT = 0x06, + E_WRONG_PROTOCOL_VERSION = 0x07, + E_WRONG_INTERFACE_VERSION = 0x08, + E_MALFORMED_MESSAGE = 0x09, + E_WRONG_MESSAGE_TYPE = 0xA, + E_UNKNOWN = 0xFF +}; + +enum class subscription_type_e : uint8_t { + SU_RELIABLE_AND_UNRELIABLE = 0x00, + SU_PREFER_UNRELIABLE = 0x01, + SU_PREFER_RELIABLE = 0x02, + SU_UNRELIABLE = 0x03, + SU_RELIABLE = 0x04, +}; + +enum class routing_state_e : uint8_t { + RS_RUNNING = 0x00, + RS_SUSPENDED = 0x01, + RS_RESUMED = 0x02, + RS_SHUTDOWN = 0x03, + RS_DIAGNOSIS = 0x04, + RS_UNKNOWN = 0xFF +}; + +enum class offer_type_e : uint8_t { + OT_LOCAL = 0x00, + OT_REMOTE = 0x01, + OT_ALL = 0x02, +}; + +} // namespace vsomeip + +#endif // VSOMEIP_ENUMERATION_TYPES_HPP diff --git a/interface/vsomeip/error.hpp b/interface/vsomeip/error.hpp new file mode 100644 index 0000000..1136957 --- /dev/null +++ b/interface/vsomeip/error.hpp @@ -0,0 +1,26 @@ +// 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_ERROR_HPP +#define VSOMEIP_ERROR_HPP + +#include + +namespace vsomeip { + +enum class error_code_e : uint8_t { + CONFIGURATION_MISSING, + PORT_CONFIGURATION_MISSING, + CLIENT_ENDPOINT_CREATION_FAILED, + SERVER_ENDPOINT_CREATION_FAILED, + SERVICE_PROPERTY_MISMATCH +}; + +extern const char *ERROR_INFO[]; + +} // namespace vsomeip + +#endif // VSOMEIP_ERROR_HPP + diff --git a/interface/vsomeip/export.hpp b/interface/vsomeip/export.hpp new file mode 100644 index 0000000..a8577ee --- /dev/null +++ b/interface/vsomeip/export.hpp @@ -0,0 +1,30 @@ +// 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 __EXPORT__HPP__ +#define __EXPORT__HPP__ + +#if _WIN32 + #define VSOMEIP_EXPORT __declspec(dllexport) + #define VSOMEIP_EXPORT_CLASS_EXPLICIT + + #if VSOMEIP_DLL_COMPILATION + #define VSOMEIP_IMPORT_EXPORT __declspec(dllexport) + #else + #define VSOMEIP_IMPORT_EXPORT __declspec(dllimport) + #endif + + #if VSOMEIP_DLL_COMPILATION_CONFIG + #define VSOMEIP_IMPORT_EXPORT_CONFIG __declspec(dllexport) + #else + #define VSOMEIP_IMPORT_EXPORT_CONFIG __declspec(dllimport) + #endif +#else + #define VSOMEIP_EXPORT + #define VSOMEIP_IMPORT_EXPORT + #define VSOMEIP_IMPORT_EXPORT_CONFIG +#endif + +#endif diff --git a/interface/vsomeip/function_types.hpp b/interface/vsomeip/function_types.hpp new file mode 100644 index 0000000..aa086dd --- /dev/null +++ b/interface/vsomeip/function_types.hpp @@ -0,0 +1,22 @@ +// Copyright (C) 2016-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_FUNCTION_TYPES_HPP +#define VSOMEIP_FUNCTION_TYPES_HPP + +#include +#include + +namespace vsomeip { + +class payload; + +typedef std::function< + bool (const std::shared_ptr &, + const std::shared_ptr &) > epsilon_change_func_t; + +} // namespace vsomeip + +#endif // VSOMEIP_FUNCTION_TYPES_HPP diff --git a/interface/vsomeip/handler.hpp b/interface/vsomeip/handler.hpp new file mode 100644 index 0000000..bcb2aa8 --- /dev/null +++ b/interface/vsomeip/handler.hpp @@ -0,0 +1,33 @@ +// 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_HANDLER_HPP +#define VSOMEIP_HANDLER_HPP + +#include +#include + +#include + +namespace vsomeip { + +class message; + +typedef std::function< void (state_type_e) > state_handler_t; +typedef std::function< void (const std::shared_ptr< message > &) > message_handler_t; +typedef std::function< void (service_t, instance_t, bool) > availability_handler_t; +typedef std::function< bool (client_t, bool) > subscription_handler_t; +typedef std::function< void (const uint16_t) > error_handler_t; +typedef std::function< void (const service_t, const instance_t, const eventgroup_t, + const event_t, const uint16_t) > subscription_status_handler_t; +typedef std::function< void (client_t, bool, std::function< void (const bool) > )> async_subscription_handler_t; + +typedef std::function< void (const std::vector> &_services) > offered_services_handler_t; +typedef std::function< void () > watchdog_handler_t; + + +} // namespace vsomeip + +#endif // VSOMEIP_HANDLER_HPP diff --git a/interface/vsomeip/internal/deserializable.hpp b/interface/vsomeip/internal/deserializable.hpp new file mode 100644 index 0000000..5d8ebcc --- /dev/null +++ b/interface/vsomeip/internal/deserializable.hpp @@ -0,0 +1,24 @@ +// 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_DESERIALIZABLE_HPP +#define VSOMEIP_DESERIALIZABLE_HPP + +#include + +namespace vsomeip { + +class deserializer; + +class deserializable { +public: + VSOMEIP_EXPORT virtual ~deserializable() { + } + VSOMEIP_EXPORT virtual bool deserialize(deserializer *_from) = 0; +}; + +} // namespace vsomeip + +#endif // VSOMEIP_SERIALIZABLE_HPP diff --git a/interface/vsomeip/internal/serializable.hpp b/interface/vsomeip/internal/serializable.hpp new file mode 100644 index 0000000..0791419 --- /dev/null +++ b/interface/vsomeip/internal/serializable.hpp @@ -0,0 +1,30 @@ +// 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_SERIALIZABLE_HPP +#define VSOMEIP_SERIALIZABLE_HPP + +#include + +namespace vsomeip { + +class serializer; + +/** + * Abstract base class for element that can be serialized. + */ +class serializable { +public: + VSOMEIP_EXPORT virtual ~serializable() {} + + /** + * \brief serialize the content of the object + */ + VSOMEIP_EXPORT virtual bool serialize(serializer *_to) const = 0; +}; + +} // namespace vsomeip + +#endif // VSOMEIP_SERIALIZABLE_HPP diff --git a/interface/vsomeip/message.hpp b/interface/vsomeip/message.hpp new file mode 100644 index 0000000..4a68a54 --- /dev/null +++ b/interface/vsomeip/message.hpp @@ -0,0 +1,52 @@ +// 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_MESSAGE_HPP +#define VSOMEIP_MESSAGE_HPP + +#include + +#include + +namespace vsomeip { + +class payload; + +/** + * + * \defgroup vsomeip + * + * @{ + * + */ + +/** + * \brief Implements regular SOME/IP messages. + * + * This class extends @ref message_base by an unstructured payload. Except + * SOME/IP Service Discovery messages, all SOME/IP messages within vsomeip + * are represented by message objects. + */ + +class message: virtual public message_base { +public: + virtual ~message() {} + + /** + * \brief Returns a pointer to the message payload. + */ + virtual std::shared_ptr get_payload() const = 0; + + /** + * \brief Set the message payload. + */ + virtual void set_payload(std::shared_ptr _payload) = 0; +}; + +/** @} */ + +} // namespace vsomeip + +#endif // VSOMEIP_MESSAGE_HPP diff --git a/interface/vsomeip/message_base.hpp b/interface/vsomeip/message_base.hpp new file mode 100644 index 0000000..60c80e6 --- /dev/null +++ b/interface/vsomeip/message_base.hpp @@ -0,0 +1,212 @@ +// 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_MESSAGE_BASE_HPP +#define VSOMEIP_MESSAGE_BASE_HPP + +#include +#include +#include + +#include +#include + +namespace vsomeip { + +/** + * + * \defgroup vsomeip + * + * @{ + * + */ + +/** + * \brief Base class to implement SOME/IP messages. + * + * This class implements the SOME/IP message header and connects to the + * serialzing/deserializing functionalities. The class is inherited by + * the message classes within ::vsomeip and vsomeip::sd that add the + * payload representations for regular and Service Discovery messages. + */ +class message_base + : public serializable, + public deserializable { +public: + VSOMEIP_EXPORT virtual ~message_base() {}; + + /** + * \brief Returns the message identifier. + * + * The method returns the message identifier that consists of + * service identifier and method identifier. + */ + VSOMEIP_EXPORT virtual message_t get_message() const = 0; + /** + * \brief Set the message identifier. + * + * The methods sets service identifier and method identifier in + * a single call. + * + * \param _message The new message identifier. + */ + VSOMEIP_EXPORT virtual void set_message(message_t _message) = 0; + + /** + * \brief Returns the service identifier from the message header. + */ + VSOMEIP_EXPORT virtual service_t get_service() const = 0; + + /** + * \brief Set the service identifier in the message header. + */ + VSOMEIP_EXPORT virtual void set_service(service_t _service) = 0; + + /** + * \brief Returns the instance identifier. + * + * The instance identifier is _not_ part of the SOME/IP header. It is + * either derived from the incoming message (local) or from the port + * that was used to send a message (external). + */ + VSOMEIP_EXPORT virtual instance_t get_instance() const = 0; + + /** + * \brief Set the instance identifier in the message header. + * + * To address the correct service instance, vsomeip uses the instance + * identifier. For external services it is mapped to a IP address and port + * combination before the message is sent. For internal messages is + * transferred as additional data appended to the SOME/IP messages. + * Therefore, before sending a message, a user application must set the + * instance identifier. + */ + VSOMEIP_EXPORT virtual void set_instance(instance_t _instance) = 0; + + /** + * \brief Get the method/event identifier from the message header. + */ + VSOMEIP_EXPORT virtual method_t get_method() const = 0; + + /** + * \brief Set the method/event identifier in the message header. + */ + VSOMEIP_EXPORT virtual void set_method(method_t _method) = 0; + + /** + * \brief Get the payload length from the message header. + */ + VSOMEIP_EXPORT virtual length_t get_length() const = 0; + + /** + * \brief Get the request identifier from the message header. + * + * The request identifier consists of the client identifier and the + * session identifier. As it does really make sense to set it as + * a whole, setting is not supported. + */ + VSOMEIP_EXPORT virtual request_t get_request() const = 0; + + /** + * \brief Set the client identifier in the message header. + */ + VSOMEIP_EXPORT virtual client_t get_client() const = 0; + + /** + * \brief Set the client identifier in the message header. + * + * For requests this is automatically done by @ref application::send. + * For notications this is not needed. + */ + VSOMEIP_EXPORT virtual void set_client(client_t _client) = 0; + + /** + * \brief Get the session identifier from the message header. + */ + VSOMEIP_EXPORT virtual session_t get_session() const = 0; + + /** + * \brief Set the session identifier in the message header. + * + * For requests this is automatically done by @ref application::send + * For notifications it is not needed to set the session identifier. + */ + VSOMEIP_EXPORT virtual void set_session(session_t _session) = 0; + + /** + * \brief Get the protocol version from the message header. + * + * As the protocol version is a fixed value for a vsomeip implementation, + * it cannot be set. + */ + VSOMEIP_EXPORT virtual protocol_version_t get_protocol_version() const = 0; + + /** + * \brief Get the interface version from the message header. + */ + VSOMEIP_EXPORT virtual interface_version_t get_interface_version() const = 0; + + /** + * \brief Set the interface version in the message header. + */ + VSOMEIP_EXPORT virtual void set_interface_version(interface_version_t _version) = 0; + + /** + * \brief Get the message type from the message header. + */ + VSOMEIP_EXPORT virtual message_type_e get_message_type() const = 0; + + /** + * \brief Set the message type in the message header. + */ + VSOMEIP_EXPORT virtual void set_message_type(message_type_e _type) = 0; + + /** + * \brief Get the return code from the message header. + */ + VSOMEIP_EXPORT virtual return_code_e get_return_code() const = 0; + + /** + * \brief Set the return code in the message header. + */ + VSOMEIP_EXPORT virtual void set_return_code(return_code_e _code) = 0; + + /** + * \brief Return the transport mode that was/will be used to send the message. + */ + VSOMEIP_EXPORT virtual bool is_reliable() const = 0; + + /** + * \brief Set the transport mode that will be used to send the message. + */ + VSOMEIP_EXPORT virtual void set_reliable(bool _is_reliable) = 0; + + /** + * \brief Return whether or not the message is an initial event. + */ + VSOMEIP_EXPORT virtual bool is_initial() const = 0; + + /** + * \brief Set whether or not the message is an initial event. + */ + VSOMEIP_EXPORT virtual void set_initial(bool _is_initial) = 0; + + /** + * \brief Return whether or not the CRC value received is valid. + */ + VSOMEIP_EXPORT virtual bool is_valid_crc() const = 0; + + /** + * \brief Set whether or not the CRC value received is valid. + */ + VSOMEIP_EXPORT virtual void set_is_valid_crc(bool _is_valid_crc) = 0; + +}; + +/** @} */ + +} // namespace vsomeip + +#endif // VSOMEIP_MESSAGE_BASE_HPP diff --git a/interface/vsomeip/payload.hpp b/interface/vsomeip/payload.hpp new file mode 100644 index 0000000..b9b8f61 --- /dev/null +++ b/interface/vsomeip/payload.hpp @@ -0,0 +1,106 @@ +// 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_PAYLOAD_HPP +#define VSOMEIP_PAYLOAD_HPP + +#include + +#include +#include + +#include +#include + +namespace vsomeip { + +/** + * + * \defgroup vsomeip + * + * @{ + * + */ + +/** + * + * \brief This class implements an array of bytes to be used as + * payload for SOME/IP messages. + * +*/ +class payload: public serializable, public deserializable { +public: + VSOMEIP_EXPORT virtual ~payload() {} + + /** + * \brief Returns true if the given payload is equal to this one. + * + * \param _other Payload that shall be compared to this payload. + */ + VSOMEIP_EXPORT virtual bool operator ==(const payload &_other) = 0; + + /** + * \brief Returns pointer to the payload content + */ + VSOMEIP_EXPORT virtual byte_t * get_data() = 0; + + /** + * \brief Returns constant pointer to the payload content + */ + VSOMEIP_EXPORT virtual const byte_t * get_data() const = 0; + + /** + * \brief Copies the given data array to the payload object. + * + * The current payload content is replaced by the data provided. + * The given buffer remains untouched. + * + * \param _data Pointer to a data buffer. + * \param _length Length of the data buffer. + */ + VSOMEIP_EXPORT virtual void set_data(const byte_t *_data, + length_t _length) = 0; + + /** + * \brief Copies the given data array to the payload object. + * + * The current payload content is replaced by the data provided. + * The given buffer remains untouched. + * + * \param _data Vector containing the data + */ + VSOMEIP_EXPORT virtual void set_data( + const std::vector &_data) = 0; + + /** + * \brief Returns the length of the payload content. + */ + VSOMEIP_EXPORT virtual length_t get_length() const = 0; + + /** + * \brief Set the maximum length of the payload content. + * + * This function must be called before directly copying data using the + * pointer to the internal buffer. + */ + VSOMEIP_EXPORT virtual void set_capacity(length_t _length) = 0; + + /** + * \brief Moves the given data array to the payload object. + * + * The current payload content is replaced by the data provided. + * The given buffer is owned by the payload object afterwards. + * + * \param _data Vector containing the data + */ + VSOMEIP_EXPORT virtual void set_data( + std::vector &&_data) = 0; +}; + +/** @} */ + +} // namespace vsomeip + +#endif // VSOMEIP_PAYLOAD_HPP diff --git a/interface/vsomeip/plugin.hpp b/interface/vsomeip/plugin.hpp new file mode 100644 index 0000000..4d608f1 --- /dev/null +++ b/interface/vsomeip/plugin.hpp @@ -0,0 +1,89 @@ +// Copyright (C) 2016-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_PLUGIN_HPP +#define VSOMEIP_PLUGIN_HPP + +#include + +#if WIN32 + #if VSOMEIP_DLL_COMPILATION_PLUGIN + #define VSOMEIP_IMPORT_EXPORT_PLUGIN __declspec(dllexport) + #else + #define VSOMEIP_IMPORT_EXPORT_PLUGIN __declspec(dllimport) + #endif +#else + #define VSOMEIP_IMPORT_EXPORT_PLUGIN +#endif + +#define VSOMEIP_PLUGIN_INIT_SYMBOL "vsomeip_plugin_init" + +namespace vsomeip { + +enum class plugin_type_e : uint8_t { + APPLICATION_PLUGIN, + PRE_CONFIGURATION_PLUGIN, + CONFIGURATION_PLUGIN, + SD_RUNTIME_PLUGIN +}; + +class plugin; +typedef std::shared_ptr (*create_plugin_func)(); +typedef create_plugin_func (*plugin_init_func)(); + +/** + * Base class for all plug-ins + */ +class VSOMEIP_IMPORT_EXPORT_PLUGIN plugin { +public: + virtual ~plugin() {} + + virtual uint32_t get_plugin_version() const = 0; + virtual const std::string &get_plugin_name() const = 0; + virtual plugin_type_e get_plugin_type() const = 0; +}; + +template +class plugin_impl : public plugin { +public: + static std::shared_ptr get_plugin() { + return std::make_shared(); + } + + plugin_impl(const std::string &_name, uint32_t _version, + plugin_type_e _type) { + name_ = _name; + version_ = _version; + type_ = _type; + } + + const std::string &get_plugin_name() const { + return name_; + } + + uint32_t get_plugin_version() const { + return version_; + } + + plugin_type_e get_plugin_type() const { + return type_; + } + +private: + uint32_t version_; + std::string name_; + plugin_type_e type_; +}; + +#define VSOMEIP_PLUGIN(class_name) \ + extern "C" { \ + VSOMEIP_EXPORT vsomeip::create_plugin_func vsomeip_plugin_init() { \ + return class_name::get_plugin; \ + } \ + } + +} // namespace vsomeip + +#endif // VSOMEIP_PLUGIN_HPP diff --git a/interface/vsomeip/plugins/application_plugin.hpp b/interface/vsomeip/plugins/application_plugin.hpp new file mode 100644 index 0000000..3d5cce1 --- /dev/null +++ b/interface/vsomeip/plugins/application_plugin.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2016-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_APPLICATION_PLUGIN_HPP +#define VSOMEIP_APPLICATION_PLUGIN_HPP + +#include +#include + +#include + +// Version should be incremented on breaking API change +#define VSOMEIP_APPLICATION_PLUGIN_VERSION 1 + +namespace vsomeip { + +enum class application_plugin_state_e : uint8_t { + STATE_INITIALIZED, + STATE_STARTED, + STATE_STOPPED +}; + +/** + * The application plug-in can be used to extend application behavior + * via an module/plug-in. + */ +class application_plugin { +public: + virtual ~application_plugin() {} + + // Called by vSomeIP to inform an application plug-in about its actual state + // Call should not be blocked from plug-in as there is no threading. + // The caller thread of "application::init/::start/::stop" will inform the plug-in. + virtual void on_application_state_change(const std::string _application_name, + const application_plugin_state_e _app_state) = 0; +}; + +} + +#endif // VSOMEIP_APPLICATION_PLUGIN_HPP diff --git a/interface/vsomeip/plugins/pre_configuration_plugin.hpp b/interface/vsomeip/plugins/pre_configuration_plugin.hpp new file mode 100644 index 0000000..6155796 --- /dev/null +++ b/interface/vsomeip/plugins/pre_configuration_plugin.hpp @@ -0,0 +1,29 @@ +// Copyright (C) 2016-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_PRE_CONFIGURATION_PLUGIN_HPP +#define VSOMEIP_PRE_CONFIGURATION_PLUGIN_HPP + +#include + +// Version should be incremented on breaking API change +#define VSOMEIP_PRE_CONFIGURATION_PLUGIN_VERSION 1 + +namespace vsomeip { +/** + * The pre configuration plug-in can be used to extend configuration load behavior + * via an module/plug-in. + */ +class pre_configuration_plugin { +public: + virtual ~pre_configuration_plugin() {} + + // Plug-In should return a valid path to a vSomeIP configuration. + // vSomeIP will use this path for config loading if such a plug-in is availablel. + virtual std::string get_configuration_path() = 0; +}; +} + +#endif // VSOMEIP_PRE_CONFIGURATION_PLUGIN_HPP diff --git a/interface/vsomeip/primitive_types.hpp b/interface/vsomeip/primitive_types.hpp new file mode 100644 index 0000000..9f6c84a --- /dev/null +++ b/interface/vsomeip/primitive_types.hpp @@ -0,0 +1,49 @@ +// 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_PRIMITIVE_TYPES_HPP +#define VSOMEIP_PRIMITIVE_TYPES_HPP + +#include +#include + +namespace vsomeip { + +typedef uint32_t message_t; +typedef uint16_t service_t; +typedef uint16_t method_t; +typedef uint16_t event_t; + +typedef uint16_t instance_t; +typedef uint16_t eventgroup_t; + +typedef uint8_t major_version_t; +typedef uint32_t minor_version_t; + +typedef uint32_t ttl_t; + +typedef uint32_t request_t; +typedef uint16_t client_t; +typedef uint16_t session_t; + +typedef uint32_t length_t; + +typedef uint8_t protocol_version_t; +typedef uint8_t interface_version_t; + +typedef uint8_t byte_t; + +// Addresses +typedef std::array ipv4_address_t; +typedef std::array ipv6_address_t; + +typedef std::string trace_channel_t; + +typedef std::string trace_filter_type_t; + +typedef std::uint16_t pending_subscription_id_t; +} // namespace vsomeip + +#endif // VSOMEIP_PRIMITIVE_TYPES_HPP diff --git a/interface/vsomeip/runtime.hpp b/interface/vsomeip/runtime.hpp new file mode 100644 index 0000000..ae54e19 --- /dev/null +++ b/interface/vsomeip/runtime.hpp @@ -0,0 +1,216 @@ +// 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_RUNTIME_HPP +#define VSOMEIP_RUNTIME_HPP + +#include +#include +#include + +#include +#include + +namespace vsomeip { + +class application; +class message; +class payload; + +/** + * + * \defgroup vsomeip + * + * The vsomeip module contains all elements a user applications needs to: + * + * - offer SOME/IP service instances + * - request SOME/IP service instances + * - offer SOME/IP eventgroups + * - subscribe to SOME/IP eventgroups + * - send and receive SOME/IP messages (request/response) + * - implement SOME/IP events and fields + * + * @{ + * + */ + +/** + * + * \brief Singleton class containing all public resource management + * facilities of vsomeip. + * + * The methods of this class shall be used to create instances of all the + * classes needed to facilitate SOME/IP communication. In particular, it is + * the entry point to create instances of the @ref application class that + * contains the main public API of vsomeip. + * + */ +class VSOMEIP_IMPORT_EXPORT runtime { +public: + + static std::string get_property(const std::string &_name); + static void set_property(const std::string &_name, const std::string &_value); + + static std::shared_ptr get(); + + virtual ~runtime() { + } + + /** + * + * \brief Creates a vsomeip application object. + * + * An application object manages service offers and requests as well as + * event subscriptions. It allows to register user application functions + * as callbacks that are called on specific events during runtime, e.g + * to react on incoming SOME/IP messages. + * An application object is identified by a unique name that is also used + * in (and therefore has to match) the configuration files of vsomeip. If + * the name is left empty, the application name is taken from the + * environment variable "VSOMEIP_APPLICATION_NAME" + * + * \param _name Name of the application on the system. + * + */ + virtual std::shared_ptr create_application( + const std::string &_name = "") = 0; + + /** + * + * \brief Constructs an empty message object. + * + * The message can then be used to call @application::send to send a + * SOME/IP message. The user application is responsible for setting + * the message type, the service instance and the message payload + * after this call and before calling @application::send. + * + * \param _reliable Determines whether this message shall be sent + * over a reliable connection (TCP) or not (UDP). + * + */ + virtual std::shared_ptr create_message( + bool _reliable = false) const = 0; + /** + * + * \brief Constructs an empty request message. + * + * The message can then be used to call @ref application::send to send a + * SOME/IP message. The message type is set to REQUEST after the + * call and the request identifier is automatically set during the + * @ref application::send call. + * + * The user application is responsible for setting the service instance + * and the payload. + * + * \param _reliable Determines whether this message shall be sent + * over a reliable connection (TCP) or not (UDP). + * + */ + virtual std::shared_ptr create_request( + bool _reliable = false) const = 0; + + /* + * \brief Constructs an empty response message from a given request + * message. + * + * The message can then be used to call @ref application::send to send a + * SOME/IP message. The message type is set to RESPONSE after the + * call and the request identifier is automatically set from the + * request message. + * + * The user application is responsible for setting the service instance + * and the payload. + * + * \param _request The request message that shall be answered by + * the response message. + * + */ + virtual std::shared_ptr create_response( + const std::shared_ptr &_request) const = 0; + + /** + * + * \brief Creates an empty notification message. + * + * The message can then be used to call @ref application::send to send a + * SOME/IP message. The message type is set to NOTIFICATION after the + * call. + * + * The user application is responsible for setting the service instance + * and the payload. + * + * \param _reliable Determines whether this message shall be sent + * over a reliable connection (TCP) or not (UDP). + * + * Note: Creating notification messages and sending them using + * @ref application::send is possible but not the standard way of sending + * notification with vsomeip. The standard way is calling + * @ref application::offer_event and setting the value using the + * @ref application::notify / @ref application::notify_one methods. + * + */ + virtual std::shared_ptr create_notification( + bool _reliable = false) const = 0; + + /** + * + * \brief Creates an empty payload object. + * + */ + virtual std::shared_ptr create_payload() const = 0; + + /** + * + * \brief Creates a payload object filled with the given data. + * + * \param _data Bytes to be copied into the payload object. + * \param _size Number of bytes to be copied into the payload object. + * + */ + virtual std::shared_ptr create_payload( + const byte_t *_data, uint32_t _size) const = 0; + + /** + * + * \brief Creates a payload object filled with the given data. + * + * \param _data Bytes to be copied into the payload object. + * + */ + virtual std::shared_ptr create_payload( + const std::vector &_data) const = 0; + + /** + * + * \brief Retrieves the application object for the application with the + * given name. + * + * If no such application is found, an empty shared_ptr is returned + * (nullptr). + * + * \param _name Name of the application to be found. + * + */ + virtual std::shared_ptr get_application( + const std::string &_name) const = 0; + + /** + * + * \brief Removes the application object for the application with the + * given name. + * + * If no such application is found, this is a null operation. + * + * \param _name Name of the application to be removed. + * + */ + virtual void remove_application( const std::string &_name) = 0; +}; + +/** @} */ + +} // namespace vsomeip + +#endif // VSOMEIP_RUNTIME_HPP diff --git a/interface/vsomeip/vsomeip.hpp b/interface/vsomeip/vsomeip.hpp new file mode 100644 index 0000000..90940b2 --- /dev/null +++ b/interface/vsomeip/vsomeip.hpp @@ -0,0 +1,20 @@ +// 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_VSOMEIP_HPP +#define VSOMEIP_VSOMEIP_HPP + +/** + * \brief The central vsomeip header. Include this to use vsomeip. + */ + +#include +#include +#include +#include +#include +#include + +#endif // VSOMEIP_VSOMEIP_HPP -- cgit v1.2.1