代码解析3"/>
[someip专题]vsomeip代码解析3
代码下载,大家请参考 ,以下则直接说明每个文件,每个函数,作用,共同记录学习GitHub - COVESA/vsomeip: An implementation of Scalable service-Oriented MiddlewarE over IP
1someip基础知识
关于SOME/IP的理解_AgingMoon的博客-CSDN博客_someip
2.vsomeip 安装使用
[someip专题]vsomeip使用以及代码解析1_AgingMoon的博客-CSDN博客
3.hello world代码解析
[someip专题]vsomeip代码解析2_AgingMoon的博客-CSDN博客
4. application 解析
4.1 vsomeip application主要功能
主要功能包括
功能 | 说明 |
offer service | 提供服务 |
stop offer service | 停止提供服务 |
publish eventgroup | 发布事件组 |
stop publish eventgroup | 停止发布事件组 |
send request | 发送请求 |
send response | 发送响应 |
trigger event | 事件驱动 |
update field | 更新域 |
receive message | 接收消息 |
subscribe eventgroup | 订阅事件组 |
unsubscribe eventgroup | 取消订阅事件组 |
request service | 请求服务 |
release service | 释放服务 |
4.2 vsomeip application 静态结构
以下针对application中,涉及到的函数进行说明
4.3 vsomeip runtime class
runtime class 接口声明在 interface/vsomeip/runtime.hpp 文件中
runtime 主要包含,vsomeip公共资源的管理,是一个单例类,是application类,创建实例化的入口,前面我们也提到 用runtime 去创建application。
/**** \brief 创建vsomeip application 对象.**应用对象用于管理服务提供,和请求,以及事件订阅,应用对象的名称通过配置文件唯一识别, *如果名字为空,则会从环境变量VSOMEIP_APPLICATION_NAME中获取** \param _name Name of the application **/virtual std::shared_ptr<application> create_application(const std::string &_name = "") = 0;
/**** \brief 构建一个空的 message 对象.** \param _reliable 可靠性由TCP连接还是UDP连接决定**/virtual std::shared_ptr<message> create_message(bool _reliable = false) const = 0;
/**** \brief 构建空的 request message.**消息内容和服务实例,有用户设定**/virtual std::shared_ptr<message> create_request(bool _reliable = false) const = 0;
/** \brief 从给定的请求消息 构建 empty response message **/virtual std::shared_ptr<message> create_response(const std::shared_ptr<message> &_request) const = 0;
/**** \brief 创建空的 notification message.** 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<message> create_notification(bool _reliable = false) const = 0;
/**** \brief 查询应用对象**/virtual std::shared_ptr<application> get_application(const std::string &_name) const = 0;
/**** \brief 移除应用对象* \param _name Name of the application to be removed.**/virtual void remove_application( const std::string &_name) = 0;
runtime class 实现在 runtime 文件中,被runtime_impl 继承
创建应用的方式是,根据应用的名称进行创建一个aplication_impl对象,并保存在application_[its_name_]中。
获取应用的方式是,根据名字查找application_[_name],查到即返回该对象;
创建消息的方式是,指定是否可靠(TCP/UDP),创建一个message_impl对象,指定协议版本,返回码,可靠性,接口版本;
创建消息请求的方式是,指定是否可靠,创建一个message_impl对象,指定协议版本,返回码,可靠性,接口版本,以及 消息类型为 REQUEST
创建消息请求的方式是,创建一个message_impl对象,根据请求的消息,设定请求service-instance-method-client-session, 设定协议版本,返回码,可靠性 以及消息类型为RESPONSE。
创建消息通知的方式是,创建一个message_impl对象,设定消息类型为NOTIFICATION
创建payload方式,实例化一个payload_impl
4.4 vsomeip application class
application类定义的接口声明在interface/application.hpp中
application管理每个用户的生命周期以及所需分配的资源。
/**** \brief 获取应用的名称** Note: A user application can use several vsomeip application objects in* parallel. The application names must be set explicitly ** \return Application name**/virtual const std::string & get_name() const = 0;
/**** \brief 返回客户端ID** 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 获取诊断地址** \return diagnosis address*/virtual diagnosis_t get_diagnosis() const = 0;
/**** \brief 初始化应用 **/virtual bool init() = 0;/**** \brief 开始消息处理*/virtual void start() = 0;/*** \brief 停止消息处理**/virtual void stop() = 0;/*** \brief 处理 messages / events.**/virtual void process(int _number = VSOMEIP_ALL) = 0;/**** \brief Offers 服务实例** \param _service Service ID* \param _instance Instance ID* \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 服务实例** \param _service Service ID* \param _instance Instance ID* \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 event or field.** \param _service Service ID* \param _instance Instance ID* \param _notifier 通知ID* \param _eventgroups eventgroup ID* \param _type Pure event, selective event or field.* \param _cycle 事件周期* \param _change_resets_cycle S* \param _update_on_change * \param _epsilon_change_func * \param _reliability Either RT_UNRELIABLE or RT_RELIABLE. */virtual void offer_event(service_t _service, instance_t _instance,event_t _notifier, const std::set<eventgroup_t> &_eventgroups,event_type_e _type = event_type_e::ET_EVENT,std::chrono::milliseconds _cycle =std::chrono::milliseconds::zero(),bool _change_resets_cycle = false,bool _update_on_change = true,const epsilon_change_func_t &_epsilon_change_func = nullptr,reliability_type_e _reliability = reliability_type_e::RT_UNKNOWN) = 0;/**** \brief Stops offering event or field.** \param _service Service ID* \param _instance Instance ID* \param _event Event ID**/virtual void stop_offer_event(service_t _service,instance_t _instance, event_t _event) = 0;/**** \brief 注册应用客户端** \param _service Service ID* \param _instance Instance ID* \param _major Major service version (Default: 0xFF).* \param _minor Minor service version (Default: 0xFFFFFF).* \param _use_exclusive_proxy Create an IP endpoint**/virtual void request_service(service_t _service, instance_t _instance,major_version_t _major = ANY_MAJOR,minor_version_t _minor = ANY_MINOR) = 0;/**** \brief 去注册应用客户端*** \param _service Service ID.* \param _instance Instance ID**/virtual void release_service(service_t _service, instance_t _instance) = 0;/**** \brief 注册应用 of an event or field.*** \param _service Service ID* \param _instance Instance ID* \param _event Event ID* \param _eventgroups Eventgroup ID* \param _type Pure event, selective event or field.* \param _reliability Either RT_UNRELIABLE or RT_RELIABLE*/virtual void request_event(service_t _service, instance_t _instance,event_t _event, const std::set<eventgroup_t> &_eventgroups,event_type_e _type = event_type_e::ET_EVENT,reliability_type_e _reliability = reliability_type_e::RT_UNKNOWN) = 0;/**** \brief 去注册应用 of an event or field.** \param _service Service ID* \param _instance Instance ID* \param _event Event ID* .*/virtual void release_event(service_t _service, instance_t _instance,event_t _event) = 0;/**** \brief 订阅 eventgroup.*** \param _service Service ID* \param _instance Instance ID* \param _eventgroup Eventgroup ID* \param _major Major version number of the service.* \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,event_t _event = ANY_EVENT) = 0;/**** \brief 取消订阅eventgroup.** \param _service Service ID* \param _instance Instance ID* \param _eventgroup Eventgroup ID**/virtual void unsubscribe(service_t _service, instance_t _instance,eventgroup_t _eventgroup) = 0;/**** \brief 查询可用的服务*** \param _service Service ID* \param _instance Instance ID* \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 = ANY_MAJOR, minor_version_t _minor = ANY_MINOR) const = 0;/**** \brief 发送消息** 序列化消息,并发送到消息目标** \param _message Message object.**/virtual void send(std::shared_ptr<message> _message) = 0;/**** \brief Fire an event or field notification.** \param _service Service ID* \param _instance Instance ID* \param _event Event ID* \param _payload Serialized payload of the event.**/virtual void notify(service_t _service, instance_t _instance,event_t _event, std::shared_ptr<payload> _payload,bool _force = false) const = 0;/**** \brief Fire an event to a specific client.* \param _service Service ID* \param _instance Instance ID* \param _event Event ID* \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> _payload, client_t _client,bool _force = false) const = 0;/**** \brief 注册状态处理*** \param _handler Handler function **/virtual void register_state_handler(state_handler_t _handler) = 0;/**** \brief 去注册状态处理**/virtual void unregister_state_handler() = 0;/**** \brief 注册处理 指定的 method or event.** \param _service Service ID* \param _instance Instance ID* \param _method Method/Event ID* \param _handler Callback 函数**/virtual void register_message_handler(service_t _service,instance_t _instance, method_t _method,message_handler_t _handler) = 0;/**** \brief 反注册处理 指定的 service method/event notification.** \param _service Service ID* \param _instance Instance ID* \param _method Method/Event ID*/virtual void unregister_message_handler(service_t _service,instance_t _instance, method_t _method) = 0;/**** \brief 注册一个服务可用回调.** \param _service Service ID* \param _instance Instance ID* \param _handler Callback * \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 = ANY_MAJOR, minor_version_t _minor = ANY_MINOR) = 0;/**** \brief 反注册一个服务可用回调.** \param _service Service ID* \param _instance Instance ID* \param _handler Callback * \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 = ANY_MAJOR, minor_version_t _minor = ANY_MINOR) = 0;/**** \brief 注册一个订阅处理** \param _service Service ID* \param _instance Instance ID* \param _eventgroup Eventgroup ID* \param _handler Callback .**/virtual void register_subscription_handler(service_t _service,instance_t _instance, eventgroup_t _eventgroup,subscription_handler_t _handler) = 0;/**** \brief 注册一个异步订阅处理** \param _service Service ID* \param _instance Instance ID* \param _eventgroup Eventgroup ID* \param _handler Callback **/virtual void register_async_subscription_handler(service_t _service, instance_t _instance, eventgroup_t _eventgroup,async_subscription_handler_t _handler) = 0;/**** \brief 反注册一个异步订阅处理** \param _service Service ID* \param _instance Instance ID* \param _eventgroup Eventgroup ID**/virtual void unregister_subscription_handler(service_t _service,instance_t _instance, eventgroup_t _eventgroup) = 0;/**** \brief 清除所有的处理**/virtual void clear_all_handler() = 0;/**** \brief 说明是否包含消息路由**/virtual bool is_routing() const = 0;/*** \brief 设置路由状态** . It can be set to RUNNING, SUSPENDED, RESUMED, SHUTDOWN or UNKNOWN.** \param _routing_state the current routing state*/virtual void set_routing_state(routing_state_e _routing_state) = 0;/**** \brief 取消订阅事件组** \param _service Service ID* \param _instance Instance ID* \param _eventgroup Eventgroup ID* \param _event Event to unsubscribe */virtual void unsubscribe(service_t _service, instance_t _instance,eventgroup_t _eventgroup, event_t _event) = 0;/**** \brief 注册订阅状态侦听*** \param _service Service ID* \param _instance Instance ID* \param _eventgroup Eventgroup ID* \param _event Event ID* \param _handler A subscription status handler * \param _is_selective Flag to enable calling the provided handler */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 = false) = 0;/**** \brief 取消注册订阅状态侦听** \param _service Service ID* \param _instance Instance ID* \param _eventgroup Eventgroup ID* \param _event Event ID*/virtual void unregister_subscription_status_handler(service_t _service,instance_t _instance, eventgroup_t _eventgroup, event_t _event) = 0;/*** \brief Enables or disables calling of registered acceptance* handlers for given remote info** This method has only an effect when called on the application acting as* routing manager** \param _remote IP and port for which SD acceptance handler should be* called* \param _path Path which indicates need for offer acceptance* \param _enable enable or disable calling of offer acceptance handler*/virtual void set_sd_acceptance_required(const remote_info_t& _remote,const std::string& _path,bool _enable) = 0;/*** \brief Enables or disables calling of registered acceptance* handlers for given remote info** This method has only an effect when called on the application acting as* routing manager** \param _remotes remote infos for which SD acceptance handler should be* called* \param _enable enable or disable calling of offer acceptance handler*/typedef std::map<remote_info_t, std::string> sd_acceptance_map_type_t;virtual void set_sd_acceptance_required(const sd_acceptance_map_type_t& _remotes, bool _enable) = 0;/*** \brief Returns all configured remote info which require calling of* registered service discovery (SD) acceptance handler** This method has only an effect when called on the application acting as* routing manager** \return map with known remotes requiring SD acceptance handling*/virtual sd_acceptance_map_type_t get_sd_acceptance_required() = 0;/*** \brief Registers a handler which will be called upon reception of* a remote SD message with the sending ECU's IP address and port as* parameter** This method has only an effect when called on the application acting as* routing manager** \param _handler The handler to be called*/virtual void register_sd_acceptance_handler(sd_acceptance_handler_t _handler) = 0;/*** \brief Registers a handler which will be called upon detection of a* reboot of a remote ECU with the remote ECU's IP address as a parameter** This method has only an effect when called on the application acting as* routing manager** \param _handler The handler to be called*/virtual void register_reboot_notification_handler(reboot_notification_handler_t _handler) = 0;/*** \brief Registers a handler which will be called when the routing reached* READY state.** This method has only an effect when called on the application acting as* routing manager** \param _handler The handler to be called*/virtual void register_routing_ready_handler(routing_ready_handler_t _handler) = 0;/*** \brief Registers a handler which will be called when the routing state* changes.** This method has only an effect when called on the application acting as* routing manager** \param _handler The handler to be called*/virtual void register_routing_state_handler(routing_state_handler_t _handler) = 0;/*** \brief Update service configuration to offer a local service on the* network as well** This function is intended to take the necessary information to offer a* service remotely if it was offered only locally beforehand.* Precondition: The service must already be offered locally before* calling this method.* This function only has an effect if called on an application acting as* routing manager.** \param _service Service identifier* \param _instance Instance identifier* \param _port The port number on which the service should be offered* \param _reliable Offer via TCP or UDP* \param _magic_cookies_enabled Flag to enable magic cookies* \param _offer Offer the service or stop offering it remotely*/virtual bool update_service_configuration(service_t _service,instance_t _instance,std::uint16_t _port,bool _reliable,bool _magic_cookies_enabled,bool _offer) = 0;
application的应用实现内容较多,在下一篇中,进行详细的说明。
更多推荐
[someip专题]vsomeip代码解析3
发布评论