当前位置: 首页 > news >正文

AUTOSAR_EXP_ARAComAPI的5章笔记(2)

返回目录

5.3 Proxy Class

Proxy ClassAutoSar元模型服务接口描述中生成。 ara::com确实标准化了生成的Proxy Class的接口。一个AP产品供应商的工具链将生成一个代理实现类来精确地实现这个接口。

注意: 因为Proxy Class必须提供的接口是由ara::com定义的,所以一个通用生成器可以生成一个抽象类,应用程序开发人员可以根据这个抽象类来实现他的客户端应用程序。这非常适合自适应AutoSar SWCs的平台供应商独立开发。

ara::com期望在命名空间“proxy”中有代理相关的工件。这个命名空间通常包含在从服务定义及其上下文推导出的命名空间层次结构中。

5.3.1 Proxy Class API’s

  • FindService()

  • StartFindService()

  • StopFindService()

  • Subscribe()

  • Unsubscribe()

  • GetSubscriptionState()

  • SetSubscriptionStateChangeHandler()

  • UnsetSubscriptionStateChangeHandler()

  • GetNewSamples()

  • GetResult()

  • GetFreeSampleCount()

  • SetReceiveHandler()

  • UnsetReceiveHandler()

  • ResolveInstanceIDs()

  • Field::Get()

  • Field::Set()

5.3.2 RadarService Proxy Class Example

RadarService Proxy类的基本信息如下

class RadarServiceProxy 
{public:/*** \brief Implementation is platform vendor specific** A HandleType must contain the information that is needed to create* a proxy.** This information shall be hidden.* Since the platform vendor is responsible for creation of handles,the*/class HandleType {/*** \brief Two ServiceHandles are considered equal if they represent* the same service instance.** \param other** \return bool*/inline bool operator==(const HandleType &other) const;const ara::com::InstanceIdentifier &GetInstanceId() const;};/*** StartFindService does not need an explicit version parameter as this* is internally available in ProxyClass.* That means only compatible services are returned.** \param handler this handler gets called any time the service* availability of the services matching the given* instance criteria changes. If you use this variant of* FindService, the Communication Management has to* continuously monitor the availability of the services* and call the handler on any change.** \param instanceId which instance of the service type defined* by T shall be searched/found.** \return a handle for this search/find request, which shall* be used to stop the availability monitoring and related* firing of the given handler. (\see StopFindService())*/static ara::core::Result<ara::com::FindServiceHandle> StartFindService(ara::com::FindServiceHandler<RadarServiceProxy::HandleType> handler,ara::com::InstanceIdentifier instanceId);/*** This is an overload of the StartFindService method using an* instance specifier, which gets resolved via service instance* manifest.* \param instanceSpec instance specifier*/static ara::core::Result<ara::com::FindServiceHandle> StartFindServiceara::com::FindServiceHandler<RadarServiceProxy::HandleType> handler,ara::core::InstanceSpecifier instanceSpec);/*** Method to stop finding service request (see above)*/static void StopFindService(ara::com::FindServiceHandle handle);/*** Opposed to StartFindService(handler, instance) this version* is a "one-shot" find request, which is:* - synchronous, i.e. it returns after the find has been done* and a result list of matching service instances is* available. (list may be empty, if no matching service* instances currently exist)* - does reflect the availability at the time of the method* call. No further (background) checks of availability are* done.** \param instanceId which instance of the service type defined* by T shall be searched/found.**/static ara::core::Result<ara::com::ServiceHandleContainer<RadarServiceProxy::HandleType>>FindService(ara::com::InstanceIdentifier instanceId);/*** This is an overload of the FindService method using an* instance specifier, which gets resolved via service instance* manifest.*/static ara::core::Result<ara::com::ServiceHandleContainer<RadarServiceProxy::HandleType>>FindService(ara::core::InstanceSpecifier instanceSpec);/*** \brief The proxy can only be created using a specific* handle which identifies a service.** This handle can be a known value which is defined at* deployment or it can be obtained using the* ProxyClass::FindService method.** \param handle The identification of the service the* proxy should represent.*/explicit RadarServiceProxy(HandleType &handle);/*** proxy instances are not copy constructible.*/RadarServiceProxy(RadarServiceProxy &other) = delete;/*** proxy instances are not copy assignable*/RadarServiceProxy& operator=(const RadarServiceProxy &other) = delete;/*** \brief Public member for the BrakeEvent*/events::BrakeEvent BrakeEvent;/*** \brief Public Field for UpdateRate*/fields::UpdateRate UpdateRate;/*** \brief Public member for the Calibrate method*/methods::Calibrate Calibrate;/*** \brief Public member for the Adjust method*/methods::Adjust Adjust;/*** \brief Public member for the LogCurrentState fire-and-forget method*/methods::LogCurrentState LogCurrentState;};

5.3.3 Constructor and Handle Concept

5.3.2.中示例代码中所示,ara::com规定Proxy Class提供一个构造函数。这意味着开发人员负责创建一个Proxy实例来与可能的远程服务进行通信。ctor接收RadarServiceProxy::HandleType类型(生成的Proxy Class的内部类)的句柄参数。此时,您脑海中最直接的问题是:“这个句柄是什么,如何创建它/从哪里获得它?”

它是什么,根据以下逻辑推理,显而易见:调用ctor之后,您拥有一个与服务通信的Proxy实例,因此句柄必须包含所需的寻址信息,以便通信管理绑定的实现能够与服务取得联系。这个寻址信息具体包含什么完全取决于绑定实现/技术传输层

这已经部分回答了“如何创建/从哪里获得”的问题:根据AUTOSAR 核心概念,对于一个应用程序开发人员来说,真正的创建是不可能的,因为他正在实现的应用程序AP产品和通信管理是独立的,解耦的。解决方案是,ara::com为应用程序开发人员提供了一个查找服务实例的API(5.3.4小节详细描述这个API),它返回这样包含所需寻址地址的句柄。这种方法(Proxy实例只能依赖 “FindService”API返回的句柄而创建)的共同好处是,您只能创建由现有的服务实例支持的代理

这里可能会出现一个问题:为什么是这种间接方式?即:应用程序开发人员首先必须调用ara::com提供的一些功能来获得一个句柄,然后我必须在一个ctor调用中使用它?ara::com可以直接返回一个Proxy实例,而不是“FindService”函数的句柄。

在阅读了ara::com如何处理对事件的访问(5.3.5小节)之后,可以更好地理解其中的原因。但是在此处上可以说的是,Proxy实例包含某些状态。在一些用例中,应用程序开发人员希望使用Proxy的不同实例,所有实例都“连接”到同一个服务实例。如果您只是接受存在这种情况,那么通过句柄的这种间接方式的决策就变得很清楚了: ara::com不知道应用程序开发人员每次他调用“FindService”函数时,希望总是相同的Proxy实例(显式共享状态),还是总是希望有一个新的Proxy实例。因此,通过提供这种间接/解耦方式(该函数返回完全相同Skeleton实例的句柄),让决定权掌握在ara::com用户手中。

另一方面,Proxy实例的创建既不能使用拷贝构造,也不能拷贝赋值!这是一个明确的设计策略,这是因为:Proxy实例拥有Event/Filed缓存、注册的处理程序、复杂的状态,...诸如此类。因此,当允许拷贝构造/拷贝分配时,存在资源泄露的风险,即这些拷贝被无意地完成。这从另一方面支持了通过HandleType强制构造的思想。

简而言之,强迫用户通过HandleType创建Proxy实例的决定是经过深思熟虑的。


http://www.mrgr.cn/news/19045.html

相关文章:

  • 登录-异步请求用户数据无法保存-bug
  • 后端MVC三层架构,Mybatis ,雪花算法生成唯一id
  • 计算机毕业设计Spark+PyTorch知识图谱中药推荐系统 中药数据分析可视化大屏 中药爬虫 机器学习 中药预测系统 中药情感分析 大数据毕业设计
  • Hyper-v 安装 centOS
  • Python青少年简明教程:模块
  • 记一次某中学系统越权漏洞
  • 【深入了解Java常用类】
  • LeetCode:2708. 一个小组的最大实力值(动态规划 Java)
  • 算法day20|669. 修剪二叉搜索树、将有序数组转换为二叉搜索树、538.把二叉搜索树转换为累加树
  • MySQL 锁机制详解
  • 跟我一起学FPGA (二) 语法讲解
  • 八股训练营感想
  • 多表查询_关联查询
  • 【win11】win11取消开机密码
  • 嵌入式Linux:常见信号的默认行为
  • 在vue项目中,有两个tab页,在其中一个页面调用另一个页面的方法
  • AUTOSAR_EXP_ARAComAPI的3章节笔记
  • 如何从 Bak 文件中恢复 SQL数据库?(3种方法)
  • 学习记录——day42 多态
  • 浅谈 cookie 和 session