1 // Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 
6 #ifndef VSOMEIP_APPLICATION_HPP
7 #define VSOMEIP_APPLICATION_HPP
8 
9 #include <chrono>
10 #include <memory>
11 #include <set>
12 #include <map>
13 #include <vector>
14 
15 #include "../../compat/vsomeip/constants.hpp"
16 #include "../../compat/vsomeip/enumeration_types.hpp"
17 #include "../../compat/vsomeip/function_types.hpp"
18 #include "../../compat/vsomeip/handler.hpp"
19 #include "../../compat/vsomeip/primitive_types.hpp"
20 
21 namespace vsomeip {
22 
23 class configuration;
24 class event;
25 class payload;
26 struct policy;
27 
28 /**
29  * \defgroup vsomeip
30  *
31  * @{
32  */
33 
34 /**
35  *
36  * \brief This class contains the public API of the vsomeip implementation.
37  *
38  * Due to its heavy resource footprint, it should exist once per client and can
39  * be instantiated using the API of @ref runtime. It manages the lifecycle of
40  * the vsomeip client and allocates all resources needed to communicate.
41  *
42  */
43 class application {
44 public:
~application()45     virtual ~application() {}
46 
47     /**
48      *
49      * \brief Returns the name of the application as given during creation
50      *
51      * The application name is used to identify the application. It is either
52      * set explicitely when the application object is created or configured by
53      * the environment variable VSOMEIP_APPLICATION_NAME.
54      *
55      * Note: A user application can use several vsomeip application objects in
56      * parallel. The application names must be set explicitly in this case
57      * because VSOMEIP_APPLICATION_NAME only allows to specify a single name.
58      *
59      *
60      * \return Application name
61      *
62      */
63     virtual const std::string & get_name() const = 0;
64 
65     /**
66      *
67      * \brief Returns the client identifier that was assigned to the
68      * application object.
69      *
70      * Each request sent by and each response sent to the application contain
71      * the client identifier as part of the request identifier within the
72      * SOME/IP message header. The client identifier can either be configured
73      * by the configured as part of the application node within a vsomeip
74      * configuration file or is automatically set to an unused client
75      * identifier by vsomeip. If the client identifier is automatically set,
76      * its high byte will always match the diagnosis address of the device.
77      *
78      * \return Client ID of application
79      *
80      */
81     virtual client_t get_client() const = 0;
82 
83     /**
84      *
85      * \brief Does nothing.
86      *
87      * This method exists for compatibility reasons only. It is a null
88      * operation and will be removed with the next major vsomeip version.
89      *
90      */
91     virtual void set_configuration(const std::shared_ptr<configuration> _configuration) = 0;
92 
93     /**
94      *
95      * \brief Initializes the application.
96      *
97      *  The init method must be called first after creating a vsomeip
98      *  application and executes the following steps to initialize it:
99      * - Loading the configuration from a dynamic module
100      *   - Loading the configuration from a .json file or
101      *   - Loading the configuration from compiled data (not yet available)
102      * - Determining routing configuration and initialization of the routing
103      *   itself
104      * - Installing signal handlers
105      *
106      */
107     virtual bool init() = 0;
108 
109     /**
110      *
111      * \brief Starts message processing.
112      *
113      * This method must be called after init to start message processing. It
114      * will block until the message processing is terminated using the @ref
115      * stop method or by receiving signals. It processes messages received
116      * via the sockets and uses registered callbacks to pass them to the user
117      * application.
118      *
119      */
120     virtual void start() = 0;
121 
122     /**
123      *
124      * \brief Stops message processing.
125      *
126      * This method stops message processing. Thus, @ref start will return
127      * after a call to stop.
128      *
129      */
130     virtual void stop() = 0;
131 
132     /**
133      *
134      * \brief Offers a SOME/IP service instance.
135      *
136      * The user application must call this method for each service it offers
137      * to register it at the vsomeip routing component, which makes the
138      * service visible to interested clients. Dependent on the configuration
139      * the service is available internally only or internally and externally.
140      * To offer a service to the external network, the configuration must
141      * contain a port for the offered service instance. If no such port
142      * configuration is provided, the service is not visible outside the
143      * device.
144      *
145      * \param _service Service identifier of the offered service interface.
146      * \param _instance Instance identifier of the offered service instance.
147      * \param _major Major service version (Default: 0).
148      * \param _minor Minor service version (Default: 0).
149      *
150      */
151     virtual void offer_service(service_t _service, instance_t _instance,
152             major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor =
153                     DEFAULT_MINOR) = 0;
154 
155     /**
156      *
157      * \brief Stops offering a SOME/IP service instance.
158      *
159      * The user application must call this method to withdraw a service offer.
160      *
161      * \param _service Service identifier of the offered service interface.
162      * \param _instance Instance identifer of the offered service instance.
163      * \param _major Major service version (Default: 0).
164      * \param _minor Minor service version (Default: 0).
165      *
166      */
167     virtual void stop_offer_service(service_t _service, instance_t _instance,
168             major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor =
169                     DEFAULT_MINOR) = 0;
170 
171     /**
172      *
173      * \brief Offers a SOME/IP event or field.
174      *
175      * A user application must call this method for each event/field it wants
176      * to offer. The event is registered at the vsomeip routing component that
177      * enables other applications to subscribe to the event/field as well as
178      * to get and set the field value.
179      *
180      * \param _service Service identifier of the interface containing the
181      * event.
182      * \param _instance Instance identifier of the interface containing the
183      * event.
184      * \param _event Event identifier of the offered event.
185      * \param _eventgroups List of eventgroup identifiers of the eventgroups
186      * that contain the event.
187      * \param _is_field Selector for event or field.
188      *
189      */
190     virtual void offer_event(service_t _service,
191             instance_t _instance, event_t _event,
192             const std::set<eventgroup_t> &_eventgroups,
193             bool _is_field) = 0;
194 
195     /**
196      *
197      * \brief Stops offering a SOME/IP event or field.
198      *
199      * A user application must call this method to withdraw the offer of an
200      * event or field.
201      *
202      * \param _service Service identifier of the interface that contains the
203      * event
204      * \param _instance Instance identifier of the interface that contains the
205      * event
206      * \param _event Event identifier of the offered event.
207      *
208      */
209     virtual void stop_offer_event(service_t _service,
210             instance_t _instance, event_t _event) = 0;
211 
212     /**
213      *
214      * \brief Registers the application as client of a service instance.
215      *
216      * A user application must call this method for each service instance it
217      * wants to use. The request is stored within the routing component and the
218      * application is registered as client for the service as soon as the
219      * service instance becomes available.
220      *
221      * \param _service Service identifier of the requested service interface.
222      * \param _instance Instance identifier of the requested service instance.
223      * \param _major Major service version (Default: 0xFF).
224      * \param _minor Minor service version (Default: 0xFFFFFF).
225      * \param _use_exclusive_proxy Create an IP endpoint that is exclusively
226      * used for the communication of this application to the service instance.
227      *
228      */
229     virtual void request_service(service_t _service, instance_t _instance,
230             major_version_t _major = ANY_MAJOR,
231             minor_version_t _minor = ANY_MINOR,
232             bool _use_exclusive_proxy = false) = 0;
233 
234     /**
235      *
236      * \brief Unregister the application as client of a service instance.
237      *
238      * A user application should call this method if it does not request to
239      * use the service instance any longer. The method unregisters the request
240      * a the routing component, which removes the service instance from the
241      * list of requested service instances if the call releases the last
242      * existing request for the service instance. This is important for
243      * external service instances, as the SOME/IP Service Discovery can avoid
244      * to send unnecessary Find messages.
245      *
246      * \param _service Service identifier of the offered service interface.
247      * \param _instance Instance identifier of the offered service instance.
248      *
249      */
250     virtual void release_service(service_t _service, instance_t _instance) = 0;
251 
252     /**
253      *
254      * \brief Registers the application as user of an event or field.
255      *
256      * A user application must call this method before being able to receive
257      * event or field data. The method registers the event or field at the
258      * routing component.
259      *
260      * \param _service Service identifier of the interface that contains the
261      * event.
262      * \param _instance Instance identifier of the interface that contains the
263      * event.
264      * \param _event Event identifier of the event.
265      * \param _eventgroups List of Eventgroup identifiers of the eventgroups
266      * that contain the event.
267      * \param _is_field Pure event (false) or field (true).
268      *
269      */
270     virtual void request_event(service_t _service, instance_t _instance,
271             event_t _event, const std::set<eventgroup_t> &_eventgroups,
272             bool _is_field) = 0;
273     /**
274      *
275      * \brief Unregister the application as user of an event or field.
276      *
277      *  Unregister the application as user of an event or field and completely
278      *  removes the event/field if the application is the last existing user.
279      *
280      * \param _service Service identifier of the interface that contains the
281      * event or field.
282      * \param _instance Instance identifier of the instance that contains the
283      * event or field.
284      * \param _event Event identifier of the event or field.
285      * .
286      */
287     virtual void release_event(service_t _service, instance_t _instance,
288             event_t _event) = 0;
289 
290     /**
291      *
292      * \brief Subscribes to an eventgroup.
293      *
294      * A user application must call this function to subscribe to an eventgroup.
295      * Before calling subscribe it must register all events it interested in by
296      * calls to @ref request_event. The method additionally allows to specify
297      * a specific event. If a specific event is specified, all other events of
298      * the eventgroup are not received by the application.
299      *
300      * Note: For external services, providing a specific event does not change
301      * anything regarding the message routing. The specific event is only used
302      * to filter incoming events and to determine which initial events must be
303      * sent.
304      *
305      * \param _service Service identifier of the service that contains the
306      * eventgroup.
307      * \param _instance Instance identifier of the service that contains the
308      * eventgroup.
309      * \param _eventgroup Eventgroup identifier of the eventgroup.
310      * \param _major Major version number of the service.
311      * \param _subscription_type Specifies how the events shall be received.
312      * \param _event All (Default) or a specific event.
313      *
314      */
315     virtual void subscribe(service_t _service, instance_t _instance,
316             eventgroup_t _eventgroup, major_version_t _major = DEFAULT_MAJOR,
317             subscription_type_e _subscription_type = subscription_type_e::SU_RELIABLE_AND_UNRELIABLE,
318             event_t _event = ANY_EVENT) = 0;
319 
320     /**
321      *
322      * \brief Unsubscribes from an eventgroup.
323      *
324      * \param _service Service identifier of the service that contains the
325      * eventgroup.
326      * \param _instance Instance identifier of the service that contains the
327      * eventgroup.
328      * \param _eventgroup Eventgroup identifier of the eventgroup.
329      *
330      */
331     virtual void unsubscribe(service_t _service, instance_t _instance,
332             eventgroup_t _eventgroup) = 0;
333 
334     /**
335      *
336      * \brief Retrieve for the availability of a service instance.
337      *
338      * If the version is also given, the result will only be true if the
339      * service instance is available in that specific version.
340      *
341      * \param _service Service identifier of the service instance.
342      * \param _instance Instance identifier of the service instance.
343      * \param _major Major interface version. Use ANY_MAJOR to ignore the
344      * major version.
345      * \param _minor Minor interface version. Use ANY_MINOR to ignore the
346      * minor version.
347      *
348      */
349     virtual bool is_available(service_t _service, instance_t _instance,
350             major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor = DEFAULT_MINOR) const = 0;
351 
352     /**
353      *
354      * \brief Sends a message.
355      *
356      * Serializes the specified message object, determines the taget and sends
357      * the message to the target. For requests, the request identifier is
358      * automatically built from the client identifier and the session
359      * identifier.
360      *
361      * \param _message Message object.
362      * \param _flush If set to true, the message is immediately sent. Otherwise
363      * the message might be deferred and sent together with other messages.
364      *
365      */
366     virtual void send(std::shared_ptr<message> _message, bool _flush = true) = 0;
367 
368     /**
369      *
370      * \brief Fire an event or field notification.
371      *
372      * The specified event is updated with the specified payload data.
373      * Dependent on the type of the event, the payload is distributed to all
374      * notified clients (always for events, only if the payload has changed
375      * for fields).
376      *
377      * Note: Prior to using this method, @ref offer_event has to be called by
378      * the service provider.
379      *
380      * \param _service Service identifier of the service that contains the
381      * event.
382      * \param _instance Instance identifier of the service instance that
383      * holds the event.
384      * \param _event Event identifier of the event.
385      * \param _payload Serialized payload of the event.
386      *
387      */
388     virtual void notify(service_t _service, instance_t _instance,
389                 event_t _event, std::shared_ptr<payload> _payload) const = 0;
390 
391     /**
392      *
393      * \brief Fire an event to a specific client.
394      *
395      * The specified event is updated with the specified payload data.
396      * Dependent on the type of the event, the payload is distributed to all
397      * notified clients (always for events, only if the payload has changed
398      * for fields).
399      *
400      * Note: Prior to using this method, @ref offer_event has to be called by
401      * the service provider.
402      *
403      * \param _service Service identifier of the service that contains the
404      * event.
405      * \param _instance Instance identifier of the service instance that
406      * holds the event.
407      * \param _event Event identifier of the event.
408      * \param _payload Serialized payload of the event.
409      * \param _client Target client.
410      *
411      */
412     virtual void notify_one(service_t _service, instance_t _instance,
413                 event_t _event, std::shared_ptr<payload> _payload,
414                 client_t _client) const = 0;
415 
416     /**
417      *
418      * \brief Register a state handler with the vsomeip runtime.
419      *
420      * The state handler tells if this client is successfully [de]registered
421      * at the central vsomeip routing component. This is called during the
422      * @ref start and @ref stop methods of this class to inform the user
423      * application about the registration state.
424      *
425      * \param _handler Handler function to be called on state change.
426      *
427      */
428     virtual void register_state_handler(state_handler_t _handler) = 0;
429 
430     /**
431      *
432      * \brief Unregister the state handler.
433      *
434      */
435     virtual void unregister_state_handler() = 0;
436 
437     /**
438      *
439      * \brief Registers a handler for the specified method or event.
440      *
441      * A user application must call this method to register callbacks for
442      * for messages that match the specified service, instance, method/event
443      * pattern. It is possible to specify wildcard values for all three
444      * identifiers arguments.
445      *
446      * Notes:
447      * - Only a single handler can be registered per service, instance,
448      *   method/event combination.
449      * - A subsequent call will overwrite an existing registration.
450      * - Handler registrations containing wildcards can be active in parallel
451      *   to handler registrations for specific service, instance, method/event
452      *   combinations.
453      *
454      * \param _service Service identifier of the service that contains the
455      * method or event. Can be set to ANY_SERVICE to register a handler for
456      * a message independent from a specific service.
457      * \param _instance Instance identifier of the service instance that
458      * contains the method or event. Can be set to ANY_INSTANCE to register
459      * a handler for a message independent from a specific service.
460      * \param _method Method/Event identifier of the method/event that is
461      * to be handled. Can be set to ANY_METHOD to register a handler for
462      * all methods and events.
463      * \param _handler Callback that will be called if a message arrives
464      * that matches the specified service, instance and method/event
465      * parameters.
466      *
467      */
468     virtual void register_message_handler(service_t _service,
469             instance_t _instance, method_t _method,
470             message_handler_t _handler) = 0;
471     /**
472      *
473      * \brief Unregisters the message handler for the specified service
474      * method/event notification.
475      *
476      * \param _service Service identifier of the service that contains the
477      * method or event. Can be set to ANY_SERVICE to unregister a handler for
478      * a message independent from a specific service.
479      * \param _instance Instance identifier of the service instance that
480      * contains the method or event. Can be set to ANY_INSTANCE to unregister
481      * a handler for a message independent from a specific service.
482      * \param _method Method/Event identifier of the method/event that is
483      * to be handled. Can be set to ANY_METHOD to unregister a handler for
484      * all methods and events.
485      */
486     virtual void unregister_message_handler(service_t _service,
487             instance_t _instance, method_t _method) = 0;
488 
489     /**
490      *
491      * \brief Register a callback that is called when service instances
492      * availability changes.
493      *
494      * This method allows for the registration of callbacks that are called
495      * whenever a service appears or disappears. It is possible to specify
496      * wildcards for service, instance and/or version. Additionally, the
497      * version specification is optional and defaults to DEFAULT_MAJOR
498      * /DEFAULT_MINOR.
499      *
500      * \param _service Service identifier of the service instance whose
501      * availability shall be reported. Can be set to ANY_SERVICE.
502      * \param _instance Instance identifier of the service instance whose
503      * availability shall be reported. Can be set to ANY_INSTANCE.
504      * \param _handler Callback to be called if availability changes.
505      * \param _major Major service version. The parameter defaults to
506      * DEFAULT_MAJOR and can be set to ANY_MAJOR.
507      * \param _minor Minor service version. The parameter defaults to
508      * DEFAULT_MINOR and can be set to ANY_MINOR.
509      *
510      */
511     virtual void register_availability_handler(service_t _service,
512             instance_t _instance, availability_handler_t _handler,
513             major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor = DEFAULT_MINOR) = 0;
514 
515     /**
516      *
517      * \brief Unregister an availability callback.
518      *
519      * \param _service Service identifier of the service instance whose
520      * availability shall be reported. Can be set to ANY_SERVICE.
521      * \param _instance Instance identifier of the service instance whose
522      * availability shall be reported. Can be set to ANY_INSTANCE.
523      * \param _handler Callback to be called if availability changes.
524      * \param _major Major service version. The parameter defaults to
525      * DEFAULT_MAJOR and can be set to ANY_MAJOR.
526      * \param _minor Minor service version. The parameter defaults to
527      * DEFAULT_MINOR and can be set to ANY_MINOR.     *
528      */
529     virtual void unregister_availability_handler(service_t _service,
530             instance_t _instance,
531             major_version_t _major = DEFAULT_MAJOR, minor_version_t _minor = DEFAULT_MINOR) = 0;
532 
533     /**
534      *
535      * \brief Registers a subscription handler.
536      *
537      * A subscription handler is called whenever the subscription state of an
538      * eventgroup changes. The callback is called with the client identifier
539      * and a boolean that indicates whether the client subscribed or
540      * unsubscribed.
541      *
542      * \param _service Service identifier of service instance whose
543      * subscription state is to be monitored.
544      * \param _instance Instance identifier of service instance whose
545      * subscription state is to be monitored.
546      * \param _eventgroup Eventgroup identifier of eventgroup whose
547      * subscription state is to be monitored.
548      * \param _handler Callback that shall be called.
549      *
550      */
551     virtual void register_subscription_handler(service_t _service,
552             instance_t _instance, eventgroup_t _eventgroup,
553             subscription_handler_t _handler) = 0;
554 
555     /**
556      *
557      * \brief Unregister a subscription handler.
558      *
559      * \param _service Service identifier of service instance whose
560      * subscription state is to be monitored.
561      * \param _instance Instance identifier of service instance whose
562      * subscription state is to be monitored.
563      * \param _eventgroup Eventgroup identifier of eventgroup whose
564      * subscription state is to be monitored.
565      *
566      */
567     virtual void unregister_subscription_handler(service_t _service,
568                 instance_t _instance, eventgroup_t _eventgroup) = 0;
569 
570     // [Un]Register handler for subscription errors
571     /**
572      *
573      * \brief Allows for the registration of a subscription error handler.
574      *
575      * This handler is called whenever a subscription request for an eventgroup
576      * was either accepted or rejected. The respective callback is called with
577      * ether OK (0x00) or REJECTED (0x07).
578      *
579      * \param _service Service identifier of service instance whose
580      * subscription error state is to be monitored.
581      * \param _instance Instance identifier of service instance whose
582      * subscription error state is to be monitored.
583      * \param _eventgroup Eventgroup identifier of eventgroup whose
584      * subscription error state is to be monitored.
585      * \param _handler Callback that shall be called.
586      *
587      */
588     virtual void register_subscription_error_handler(service_t _service,
589             instance_t _instance, eventgroup_t _eventgroup,
590             error_handler_t _handler) = 0;
591 
592     /**
593      *
594      * \brief Removes a registered subscription error callback.
595      *
596      * \param _service Service identifier of service instance whose
597      * error callback shall be removed.
598      * \param _instance Instance identifier of service instance whose
599      * error callback shall be removed.
600      * \param _eventgroup Eventgroup identifier of eventgroup whose
601      * error callback shall be removed.
602      *
603      */
604     virtual void unregister_subscription_error_handler(service_t _service,
605                 instance_t _instance, eventgroup_t _eventgroup) = 0;
606 
607     /**
608      *
609      * \brief Unregister all registered handlers.
610      *
611      */
612     virtual void clear_all_handler() = 0;
613 
614     /**
615      *
616      * \brief This method tells whether or not this application controls the
617      * message routing.
618      *
619      * The application that controls the routing hosts the routing manager
620      * and (optionally) loads the Service Discovery component.
621      *
622      * \return true, if this is the central routing instance, and false
623      * otherwise
624      *
625      */
626     virtual bool is_routing() const = 0;
627 
628     /**
629      *
630      * \brief Offers a SOME/IP event or field.
631      *
632      * A user application must call this method for each event/field it wants
633      * to offer. The event is registered at the vsomeip routing component that
634      * enables other applications to subscribe to the event/field as well as
635      * to get and set the field value.
636      *
637      * This version of offer_event adds some additional functionalities:
638      * - It is possible to configure a cycle time. The notification message of
639      *   this event is then resent cyclically.
640      * - The parameter _change_resets_cycle is available to control how event
641      *   notification works in case the data is updated by the application. If
642      *   set to true, an update of the data immediately leads to a
643      *   notification. Otherwise, the updated data is sent only after the
644      *   expiration of the cycle time.
645      * - It is possible to specify callback function that can be used to
646      *   implement a predicate that determines whether or not two event values
647      *   are considered different. Field notifications are only sent if the
648      *   predicate evaluates to true (or if a notify method is called with the
649      *   force flag being set).
650      *
651      * \param _service Service identifier of the interface containing the
652      * event.
653      * \param _instance Instance identifier of the interface containing the
654      * event.
655      * \param _event Event identifier of the offered event.
656      * \param _eventgroups List of eventgroup identifiers of the eventgroups
657      * that contain the event.
658      * \param _is_field Selector for event or field.
659      * \param _cycle Sets the cycle time of the event. If nonzero, data is
660      * resent cyclically after the cycle time expired.
661      * \param _change_resets_cycle Tells if a change immediately leads to
662      * a notification.
663      * \param _epsilon_change_func Predicate that determines if two given
664      * payloads are considered different.
665      *
666      * Note: The different versions of offer_event exist for compatibility
667      * reasons. They will be merged with the next major vsomeip version.
668      */
669     virtual void offer_event(service_t _service,
670             instance_t _instance, event_t _event,
671             const std::set<eventgroup_t> &_eventgroups,
672             bool _is_field,
673             std::chrono::milliseconds _cycle,
674             bool _change_resets_cycle,
675             const epsilon_change_func_t &_epsilon_change_func) = 0;
676 
677     /**
678      *
679      * \brief Fire an event or field notification.
680      *
681      * The specified event is updated with the specified payload data.
682      * Dependent on the type of the event, the payload is distributed to all
683      * notified clients (always for events, only if the payload has changed
684      * for fields).
685      *
686      * Note: Prior to using this method, @ref offer_event has to be called by
687      * the service provider.
688      *
689      * \param _service Service identifier of the service that contains the
690      * event.
691      * \param _instance Instance identifier of the service instance that
692      * holds the event.
693      * \param _event Event identifier of the event.
694      * \param _payload Serialized payload of the event.
695      * \param _force Forces the notification to be sent (even if the event
696      * is a field and the value did not change).
697      *
698      * Note: The different versions of notify do exist for compatibility
699      * reasons. They will be merged with the next major vsomeip release.
700      */
701     virtual void notify(service_t _service, instance_t _instance,
702             event_t _event, std::shared_ptr<payload> _payload,
703             bool _force) const = 0;
704 
705     /**
706      *
707      * \brief Fire an event or field notification.
708      *
709      * The specified event is updated with the specified payload data.
710      * Dependent on the type of the event, the payload is distributed to all
711      * notified clients (always for events, only if the payload has changed
712      * for fields).
713      *
714      * Note: Prior to using this method, @ref offer_event has to be called by
715      * the service provider.
716      *
717      * \param _service Service identifier of the service that contains the
718      * event.
719      * \param _instance Instance identifier of the service instance that
720      * holds the event.
721      * \param _event Event identifier of the event.
722      * \param _payload Serialized payload of the event.
723      * \param _client Target client.
724      * \param _force Forces the notification to be sent (even if the event
725      * is a field and the value did not change).
726      *
727      * Note: The different versions of notify_one do exist for compatibility
728      * reasons. They will be merged with the next major vsomeip release.
729      */
730     virtual void notify_one(service_t _service, instance_t _instance,
731             event_t _event, std::shared_ptr<payload> _payload,
732             client_t _client, bool _force) const = 0;
733 
734     typedef std::map<service_t, std::map<instance_t, std::map<major_version_t, minor_version_t >>> available_t;
735     /**
736      * \brief Returns all available instances that match the given combination
737      * of service, instance and version.
738      *
739      * This method checks the availability of the service instances that
740      * match the specified combination of service, instance and version
741      * parameters. If at least one matching service instance is available,
742      * the method returns true, otherwise it returns false. All available
743      * service instances are returned to the caller by filling the
744      * _available parameter.
745      *
746      * \param _available Map that is filled with the available instances.
747      * \param _service Service identifier that specifies which service(s)
748      * are checked.
749      * \param _instance Instance identifier that specifies which instance(s)
750      * are checked.
751      * \param _major_version Major version(s) of the service instances that
752      * are checked
753      * \param _minor_version Minor version(s) of the service instance that
754      * are checked
755      */
756     virtual bool are_available(available_t &_available,
757             service_t _service = ANY_SERVICE, instance_t _instance = ANY_INSTANCE,
758             major_version_t _major = ANY_MAJOR, minor_version_t _minor = ANY_MINOR) const = 0;
759 
760     /**
761      *
762      * \brief Fire an event or field notification.
763      *
764      * The specified event is updated with the specified payload data.
765      * Dependent on the type of the event, the payload is distributed to all
766      * notified clients (always for events, only if the payload has changed
767      * for fields).
768      *
769      * Note: Prior to using this method, @ref offer_event has to be called by
770      * the service provider.
771      *
772      * \param _service Service identifier of the service that contains the
773      * event.
774      * \param _instance Instance identifier of the service instance that
775      * holds the event.
776      * \param _event Event identifier of the event.
777      * \param _payload Serialized payload of the event.
778      * \param _force Forces the notification to be sent (even if the event
779      * is a field and the value did not change).
780      * \param _flush Must be set to ensure the event is immediately fired.
781      *
782      * Note: The different versions of notify do exist for compatibility
783      * reasons. They will be merged with the next major vsomeip release.
784      */
785     virtual void notify(service_t _service, instance_t _instance,
786             event_t _event, std::shared_ptr<payload> _payload,
787             bool _force, bool _flush) const = 0;
788 
789     /**
790      *
791      * \brief Fire an event or field notification.
792      *
793      * The specified event is updated with the specified payload data.
794      * Dependent on the type of the event, the payload is distributed to all
795      * notified clients (always for events, only if the payload has changed
796      * for fields).
797      *
798      * Note: Prior to using this method, @ref offer_event has to be called by
799      * the service provider.
800      *
801      * \param _service Service identifier of the service that contains the
802      * event.
803      * \param _instance Instance identifier of the service instance that
804      * holds the event.
805      * \param _event Event identifier of the event.
806      * \param _payload Serialized payload of the event.
807      * \param _client Target client.
808      * \param _force Forces the notification to be sent (even if the event
809      * is a field and the value did not change).
810      * \param _flush Must be set to ensure the event is immediately fired.
811      *
812      * Note: The different versions of notify_one do exist for compatibility
813      * reasons. They will be merged with the next major vsomeip release.
814      */
815     virtual void notify_one(service_t _service, instance_t _instance,
816                 event_t _event, std::shared_ptr<payload> _payload,
817                 client_t _client, bool _force, bool _flush) const = 0;
818 
819     /**
820      * \brief Set the current routing state.
821      *
822      *  The routing state impacts the behavior of the SOME/IP Service Discovery component. It
823      *  can be set to RUNNING, SUSPENDED, RESUMED, SHUTDOWN or UNKNOWN. Applications only need
824      *  to set the routing state if they are responsible for controlling the routing manager.
825      *  In most environments the vsomeip daemon is controlling the routing manager.
826      *
827      * \param _routing_state the current routing state
828      */
829     virtual  void set_routing_state(routing_state_e _routing_state) = 0;
830 
831     /**
832      *
833      * \brief Unsubscribes from an eventgroup.
834      *
835      * \param _service Service identifier of the service that contains the
836      * eventgroup.
837      * \param _instance Instance identifier of the service that contains the
838      * eventgroup.
839      * \param _eventgroup Eventgroup identifier of the eventgroup.
840      * \param _event Event to unsubscribe (pass ANY_EVENT for all events of the eventgroup)
841      */
842     virtual void unsubscribe(service_t _service, instance_t _instance,
843             eventgroup_t _eventgroup, event_t _event) = 0;
844 
845 
846     /**
847      *
848      * \brief Registers a subscription status listener.
849      *
850      * When registered such a handler it will be called for
851      * every application::subscribe call.
852      *
853      * This method is intended to replace the application::
854      * register_subscription_error_handler call in future releases.
855      *
856      * \param _service Service identifier of the service that is subscribed to.
857      * \param _instance Instance identifier of the service that is subscribed to.
858      * \param _eventgroup Eventgroup identifier of the eventgroup is subscribed to.
859      * \param _event Event indentifier of the event is subscribed to.
860      * \param _handler A subscription status handler which will be called by vSomeIP
861      * as a follow of application::subscribe.
862      */
863     virtual void register_subscription_status_handler(service_t _service,
864             instance_t _instance, eventgroup_t _eventgroup, event_t _event,
865             subscription_status_handler_t _handler) = 0;
866 
867     /**
868      *
869      * \brief Registers a subscription status listener.
870      *
871      * When registered such a handler it will be called for
872      * every application::subscribe call.
873      *
874      * This method is intended to replace the application::
875      * register_subscription_error_handler call in future releases.
876      *
877      * \param _service Service identifier of the service that is subscribed to.
878      * \param _instance Instance identifier of the service that is subscribed to.
879      * \param _eventgroup Eventgroup identifier of the eventgroup is subscribed to.
880      * \param _event Event indentifier of the event is subscribed to.
881      * \param _handler A subscription status handler which will be called by vSomeIP
882      * as a follow of application::subscribe.
883      * \param _is_selective Flag to enable calling the provided handler if the
884      * subscription is answered with a SUBSCRIBE_NACK.
885      */
886     virtual void register_subscription_status_handler(service_t _service,
887             instance_t _instance, eventgroup_t _eventgroup, event_t _event,
888             subscription_status_handler_t _handler, bool _is_selective) = 0;
889 
890     /**
891      *
892      * \brief Returns all registered services / instances on this node in an async callback.
893      *
894      * When called with a handler of type offered_services_handler_t,
895      * all at the routing manager registered services on this node get returned in a vector of
896      * service / instance pairs depending on the given _offer_type.
897      *
898      * \param _offer_type type of offered services to be returned (OT_LOCAL = 0x00, OT_REMOTE = 0x01, OT_ALL = 0x02)
899      * \param offered_services_handler_t handler which gets called with a vector of service instance pairs that are currently offered
900      */
901     virtual void get_offered_services_async(offer_type_e _offer_type, offered_services_handler_t _handler) = 0;
902 
903     /**
904      *
905      * \brief Sets a handler to be called cyclically for watchdog monitoring.
906      *
907      * The handler shall be called in the given interval, but not before start()
908      * has been called, and not after call to stop() returned.
909      *
910      * In case the application is running, i.e. start() succeeded, but the
911      * handler will not be invoke within the (approximate) interval it may
912      * be assumed that I/O or internal dispatcher threads are non-functional.
913      *
914      * \remark Accuracy of call interval is limited by clock/timer granularity
915      *         or scheduling effects, thus it may underrun or overrun by small
916      *         amount.
917      *
918      * \note Only one handler can be active at the time, thus last handler set
919      *       by calling this function will be invoked.
920      *
921      * \note To disable calling an active handler, invoke this method again,
922      *       passing nullptr as _handler and/or std::chrono::seconds::zero()
923      *       as _interval.
924      *
925      * \param _handler A watchdog handler, pass nullptr to deactivate.
926      * \param _interval Call interval in seconds, pass std::chrono::seconds::zero() to deactivate.
927      */
928     virtual void set_watchdog_handler(watchdog_handler_t _handler, std::chrono::seconds _interval) = 0;
929 
930    /**
931      *
932      * \brief Registers a subscription handler.
933      *
934      * A subscription handler is called whenever the subscription state of an
935      * eventgroup changes. The callback is called with the client identifier
936      * and a boolean that indicates whether the client subscribed or
937      * unsubscribed.
938      *
939      * \param _service Service identifier of service instance whose
940      * subscription state is to be monitored.
941      * \param _instance Instance identifier of service instance whose
942      * subscription state is to be monitored.
943      * \param _eventgroup Eventgroup identifier of eventgroup whose
944      * subscription state is to be monitored.
945      * \param _handler Callback that shall be called.
946      *
947      */
948     virtual void register_async_subscription_handler(
949             service_t _service, instance_t _instance, eventgroup_t _eventgroup,
950             async_subscription_handler_t _handler) = 0;
951 
952     /**
953      *  \brief Enables or disables calling of registered offer acceptance
954      *  handler for given IP address
955      *
956      * This method has only an effect when called on the application acting as
957      * routing manager
958      *
959      *  \param _address IP address for which offer acceptance handler should be
960      *  called
961      *  \param _path Path which indicates need for offer acceptance
962      *  \param _enable enable or disable calling of offer acceptance handler
963      */
964     virtual void set_offer_acceptance_required(ip_address_t _address,
965                                                const std::string _path,
966                                                bool _enable) = 0;
967 
968     /**
969      * \brief Returns all configured IP addresses which require calling of
970      * registered offer acceptance handler
971      *
972      * This method has only an effect when called on the application acting as
973      * routing manager
974      *
975      * \return map with known IP addresses requiring offer acceptance handling
976      */
977     typedef std::map<ip_address_t, std::string> offer_acceptance_map_type_t;
978     virtual offer_acceptance_map_type_t get_offer_acceptance_required() = 0;
979 
980     /**
981      * \brief Registers a handler which will be called upon reception of
982      * a remote offer with the offering ECU's IP address as parameter
983      *
984      * This method has only an effect when called on the application acting as
985      * routing manager
986      *
987      * \param _handler The handler to be called
988      */
989     virtual void register_offer_acceptance_handler(
990             offer_acceptance_handler_t _handler) = 0;
991 
992     /**
993      * \brief Registers a handler which will be called upon detection of a
994      * reboot of a remote ECU with the remote ECU's IP address as a parameter
995      *
996      * This method has only an effect when called on the application acting as
997      * routing manager
998      *
999      * \param _handler The handler to be called
1000      */
1001     virtual void register_reboot_notification_handler(
1002             reboot_notification_handler_t _handler) = 0;
1003 
1004     /**
1005      * \brief Registers a handler which will be called when the routing reached
1006      * READY state.
1007      *
1008      * This method has only an effect when called on the application acting as
1009      * routing manager
1010      *
1011      * \param _handler The handler to be called
1012      */
1013     virtual void register_routing_ready_handler(
1014             routing_ready_handler_t _handler) = 0;
1015 
1016     /**
1017      * \brief Registers a handler which will be called when the routing state
1018      * changes.
1019      *
1020      * This method has only an effect when called on the application acting as
1021      * routing manager
1022      *
1023      * \param _handler The handler to be called
1024      */
1025     virtual void register_routing_state_handler(
1026             routing_state_handler_t _handler) = 0;
1027 
1028     /**
1029      * \brief Update service configuration to offer a local service on the
1030      *        network as well
1031      *
1032      *  This function is intended to take the necessary information to offer a
1033      *  service remotely if it was offered only locally beforehand.
1034      *  Precondition: The service must already be offered locally before
1035      *  calling this method.
1036      *  This function only has an effect if called on an application acting as
1037      *  routing manager.
1038      *
1039      * \param _service Service identifier
1040      * \param _instance Instance identifier
1041      * \param _port The port number on which the service should be offered
1042      * \param _reliable Offer via TCP or UDP
1043      * \param _magic_cookies_enabled Flag to enable magic cookies
1044      * \param _offer Offer the service or stop offering it remotely
1045      */
1046     virtual bool update_service_configuration(service_t _service,
1047                                               instance_t _instance,
1048                                               std::uint16_t _port,
1049                                               bool _reliable,
1050                                               bool _magic_cookies_enabled,
1051                                               bool _offer) = 0;
1052 
1053     /**
1054      * \brief Update security configuration of routing manager and all local clients
1055      *        The given handler gets called with "SU_SUCCESS" if the policy for UID
1056      *        and GID was updated or added successfully. If not all clients did confirm
1057      *        the update, SU_TIMEOUT is set.
1058      *
1059      * \param _uid UID of the policy
1060      * \param _gid GID of the policy
1061      * \param _policy The security policy to apply
1062      * \param _payload serialized security policy object
1063      * \param _handler handler which gets called after all clients have
1064      *                 confirmed the policy update
1065      */
1066     virtual void update_security_policy_configuration(uint32_t _uid,
1067                                                       uint32_t _gid,
1068                                                       std::shared_ptr<policy> _policy,
1069                                                       std::shared_ptr<payload> _payload,
1070                                                       security_update_handler_t _handler) = 0;
1071 
1072     /**
1073      * \brief Remove a security configuration for routing manager and all local clients
1074      *        The given handler gets called with "SU_SUCCESS" if the policy for UID
1075      *        and GID was removed successfully. SU_UNKNOWN_USER_ID is set if the
1076      *        UID and GID was not found. If not all clients did confirm the removal,
1077      *        SU_TIMEOUT is set.
1078      *
1079      * \param _uid UID of the policy to remove
1080      * \param _gid GID of the policy to remove
1081      * \param _handler handler which gets called after all clients have
1082      *                 confirmed the policy removal
1083      */
1084     virtual void remove_security_policy_configuration(uint32_t _uid,
1085                                                       uint32_t _gid,
1086                                                       security_update_handler_t _handler) = 0;
1087 };
1088 
1089 /** @} */
1090 
1091 } // namespace vsomeip
1092 
1093 #endif // VSOMEIP_APPLICATION_HPP
1094