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

AUTOSAR_EXP_ARAComAPI的6章笔记(2)

☞返回总目录

相关总结:AutoSar AP CM实例说明符的使用方法总结

6.2 实例说明符的使用方法

一、InstanceSpecifier 的概念

InstanceSpecifier 是在 [3] 中定义的一个核心概念,它由符合特定模型元素绝对路径的模型元素 shortName 组成,表现为以 “/” 分隔的列表。通俗地说,InstanceSpecifier 在自适应平台模型和应用程序之间架起了桥梁,允许应用程序代码明确地引用由系统模型定义的资源实例。

InstanceSpecifier 所引用的实例可能有很多不同的种类:provided/required 服务实例、key/value 存储或 file 存储,或者加密资源等等。

二、InstanceSpecifier 在 C++ 语言绑定中的特征

在自适应平台的 C++ 语言绑定中,InstanceSpecifier 类有几个共同的特征:

  • 不可默认构造。
  • 可复制和可移动。
  • 可与 StringView 和其他 InstanceSpecifier 对象进行比较。
  • 可显式转换为 StringView。

有关更详细的信息,请参见 4.8.1 小节中的清单 4.2。

考虑到这些特性,创建一个非现有对象的副本或移动结果的新 InstanceSpecifier 对象的唯一方法是从一个 StringView 对象创建。

在实际应用中,这种 StringView 的内容在构造时仅进行语法检查而不进行语义检查。这意味着只要源 StringView 对象包含由仅由有效字符组成且以 “/” 分隔的名称列表,构造就会成功。该列表所描述的路径在(源自应用程序的)模型中的有效性将在不同的功能集群尝试访问或实例化由相关 InstanceSpecifier 指向的资源时进行检查。

三、使用示例

以下示例根据 [1:AUTOSAR_SWS_CommunicationManagement] 做成,InstanceSpecifier 可能通过骨架类和代理类来实例化和访问服务。InstanceSpecifier 指向与服务相关联的端口原型的实例。因此,可以为每个 PortPrototype 创建多个 InstanceSpecifier。在下面的示例中,SwComponentInstance_0 和 SwComponentInstance_1 是同一个 SwComponentPrototype 的两个实例化,它们包含 RPortPrototype RPort_3。

(一)使用骨架的实例说明符示例

#include "ara/core/instance_specifier.h"
#include "ara/com/sample/tire_skeleton.h"class TireSkeletonImplementation : 
public ara::com::sample::skeleton::TireSkeleton
{
public:using TireSkeleton::TireSkeleton;// 实现服务接口方法,如果有的话
};int main()
{const ara::core::InstanceSpecifier tire0_Instance{"/ServerExe/RootSWCP_0/Comp_Lvl1/Comp_Lvl2/SwComponentInstance_0/PPort_3"};const ara::core::InstanceSpecifier tire1_Instance{"/ServerExe/RootSWCP_0/Comp_Lvl1/Comp_Lvl2/SwComponentInstance_1/PPort_3"};TireSkeletonImplementation tire0(tire0_Instance);TireSkeletonImplementation tire1(tire1_Instance);// 当骨架实例运行、处理请求等时睡眠return 0;
}

(二)使用代理的实例说明符示例

#include "ara/core/instance_specifier.h"
#include "ara/com/sample/tire_proxy.h"int main()
{using Proxy = ara::com::sample::proxy::TireProxy;const ara::core::InstanceSpecifier tire0_Instance{"/ClientExe/RootSWCP_0/Comp_Lvl1/Comp_Lvl2/SwComponentInstance_0/RPort_3"};const ara::core::InstanceSpecifier tire1_Instance{"/ClientExe/RootSWCP_0/Comp_Lvl1/Comp_Lvl2/SwComponentInstance_1/RPort_3"};auto tire0_handles = Proxy::FindService(tire0_Instance).ValueOrThrow();auto tire1_handles = Proxy::FindService(tire1_Instance).ValueOrThrow();Proxy tire0(tire0_handles[0]);Proxy tire1(tire1_handles[0]);// 调用方法、订阅事件等return 0;
}

四、AUTOSAR Adaptive 实现与特定于进程的清单

在这些例子中,AUTOSAR Adaptive 实现会管理具有独立上下文的特定于进程的清单。这些可以在进程启动时通过例如命令行参数、环境变量、工作目录内容或任何其他特定于实现的方式来指定。

6.2.1 从用户视角看基于清单的建模和配置 / 映射

用于查找服务的 InstanceSpecifier 映射到与该服务相关联的端口的特定实例。

使用 FindService 的 C++ 示例用法

#include "ara/core/instance_specifier.h"
#include "ara/com/sample/radar_proxy.h"int main() 
{using Proxy = ara::com::sample::proxy::radarProxy;//...ara::core::InstanceSpecifier portSpecifier{"fusionExe/fusion/radar_RPort"};auto res = Proxy::FindService(portSpecifier);//....
}

在应用设计中,可执行节点指定其根软件组件原型(RootSwComponentPrototype)。反过来,软件组件原型(SwComponentPrototype)定义一个或多个端口原型(PortPrototype)。

以下是相关的 XML 示例:

<?xml version="1.0" encoding="UTF-8"?>
<AUTOSAR xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00049.xsd"><AR-PACKAGES><AR-PACKAGE><AR-PACKAGE><SHORT-NAME>apd</SHORT-NAME><AR-PACKAGE><SHORT-NAME>da</SHORT-NAME><ELEMENTS><EXECUTABLE><SHORT-NAME>fusionExe</SHORT-NAME><CATEGORY>APPLICATION_LEVEL</CATEGORY><ROOT-SW-COMPONENT-PROTOTYPE><SHORT-NAME>fusion</SHORT-NAME><APPLICATION-TYPE-TREF DEST="ADAPTIVE-APPLICATION-SW-COMPONENT-TYPE">/apd/da/fusion</APPLICATION-TYPE-TREF></ROOT-SW-COMPONENT-PROTOTYPE></EXECUTABLE><ADAPTIVE-APPLICATION-SW-COMPONENT-TYPE><SHORT-NAME>fusion</SHORT-NAME><PORTS><R-PORT-PROTOTYPE><SHORT-NAME>radar_RPort</SHORT-NAME><REQUIRED-INTERFACE-TREF DEST="SERVICE-INTERFACE">/apd/da/radar</REQUIRED-INTERFACE-TREF></R-PORT-PROTOTYPE></PORTS></ADAPTIVE-APPLICATION-SW-COMPONENT-TYPE><SOMEIP-SERVICE-INTERFACE-DEPLOYMENT><SHORT-NAME>radar_Someip</SHORT-NAME><!-- ...... --></SOMEIP-SERVICE-INTERFACE-DEPLOYMENT></ELEMENTS></AR-PACKAGE></AR-PACKAGE></AR-PACKAGE></AR-PACKAGES>
</AUTOSAR>

请参见图 6.1 中的 SOME/IP 服务接口部署。Required 服务实例(RequiredServiceInstance)和实例说明符(InstanceSpecifier)之间的映射是通过服务实例清单(Service Instance Manifest)完成的。在服务实例清单中,服务实例到端口原型映射(ServiceInstanceToPortPrototypeMapping)定义了哪个服务实例与特定根软件组件原型(RootSwComponentPrototype)内的某个端口相关联。Required 服务实例将实例 ID 指定为 Required 服务实例 ID(RequireServiceInstanceId),在下面的示例中,此值为 19。

以下是相关的 XML 示例:

<?xml version="1.0" encoding="UTF-8"?>
<AUTOSAR xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00049.xsd"><AR-PACKAGES><AR-PACKAGE><AR-PACKAGE><SHORT-NAME>apd</SHORT-NAME><AR-PACKAGE><SHORT-NAME>da</SHORT-NAME><AR-PACKAGE><ELEMENTS><SHORT-NAME>instance</SHORT-NAME><SOMEIP-SERVICE-INSTANCE-TO-MACHINE-MAPPING><SHORT-NAME>radar_RequiredServiceInstance_toMachine</SHORT-NAME><COMMUNICATION-CONNECTOR-REF DEST="ETHERNET-COMMUNICATION-CONNECTOR">/apd/da/fusionMachineDesign/fusionCommunicationConnector</COMMUNICATION-CONNECTOR-REF><SERVICE-INSTANCE-REFS><SERVICE-INSTANCE-REF DEST="REQUIRED-SOMEIP-SERVICE-INSTANCE">/apd/da/instance/radar_RequiredSomeipServiceInstance</SERVICE-INSTANCE-REF></SERVICE-INSTANCE-REFS><UDP-PORT>33111</UDP-PORT></SOMEIP-SERVICE-INSTANCE-TO-MACHINE-MAPPING><SERVICE-INSTANCE-TO-PORT-PROTOTYPE-MAPPING><SHORT-NAME>radar_RequiredServiceInstance_toPort</SHORT-NAME><PORT-PROTOTYPE-IREF><CONTEXT-ROOT-SW-COMPONENT-PROTOTYPE-REF DEST="ROOT-SW-COMPONENT-PROTOTYPE">/apd/da/fusionExe/fusion</CONTEXT-ROOT-SW-COMPONENT-PROTOTYPE-REF><TARGET-PORT-PROTOTYPE-REF DEST="R-PORT-PROTOTYPE">/apd/da/fusion/radar_RPort</TARGET-PORT-PROTOTYPE-REF></PORT-PROTOTYPE-IREF><PROCESS-REF DEST="PROCESS">/apd/da/fusion_instance1</PROCESS-REF><SERVICE-INSTANCE-REF DEST="REQUIRED-SOMEIP-SERVICE-INSTANCE">/apd/da/instance/radar_RequiredSomeipServiceInstance</SERVICE-INSTANCE-REF></SERVICE-INSTANCE-TO-PORT-PROTOTYPE-MAPPING><REQUIRED-SOMEIP-SERVICE-INSTANCE><SHORT-NAME>radar_RequiredSomeipServiceInstance</SHORT-NAME><SERVICE-INTERFACE-DEPLOYMENT-REF DEST="SOMEIP-SERVICE-INTERFACE-DEPLOYMENT">/apd/da/deployment/radar_Someip</SERVICE-INTERFACE-DEPLOYMENT-REF><!-- ...... --><REQUIRED-MINOR-VERSION>0</REQUIRED-MINOR-VERSION><REQUIRED-SERVICE-INSTANCE-ID>19</REQUIRED-SERVICE-INSTANCE-ID></REQUIRED-SOMEIP-SERVICE-INSTANCE></ELEMENTS></AR-PACKAGE></AR-PACKAGE></AR-PACKAGE></AR-PACKAGE></AR-PACKAGES>
</AUTOSAR>

注意:可执行文件可以多次启动。每个进程都使用不同的服务实例清单启动,因此在不同的进程之间,实例说明符(InstanceSpecifier)和 Required 服务实例(RequiredServiceInstance)之间的映射将有所不同。

6.2.2 仅针对所提供服务的实例 ID

实例说明符(InstanceSpecifier)和实例标识符(InstanceIdentifier)可用于唯一标识所提供的服务。这意味着客户端知道他们正在与哪个特定的服务实例进行通信。对于所提供的服务,缺少此信息。客户端无法使用实例标识符进行唯一标识,因此服务器无法确定它正在与哪个客户端进行通信。在大多数情况下,这不是问题,但是我们设想,对于安全性而言,这可能是一个问题。对于这些情况,我们建议使用方法 E2E_check 的 E2E 参数 dataID(请参见 [10:E2E Protocol Specification AUTOSAR_PRS_E2EProtocol] 中的 [PRS_E2E_00323])。


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

相关文章:

  • 【华为路由】OSPF多区域配置
  • Linux基础命令(入门)
  • 黑盒测试和白盒测试的具体方法(附加实际应用中的技巧和注意事项)
  • 深入浅出理解玻尔兹曼分布及其广泛应用
  • curl支持ssl报错:SSL certificate problem: unable to get local issuer certificate
  • Flux.using 使用说明书
  • 在做题中学习(65):Z字形变换
  • spring源码拓展点3之addBeanPostProcesser
  • 2024年9月 GESP CCF C++五级编程能力等级考试认证真题
  • 【四】企业级JavaScript开发开发者控制台
  • Q宠大乐斗鹅号提取器(基于python实现)
  • 动态规划之路径问题
  • 基于MATLAB(DCT DWT)
  • 在做题中学习(66):两数相加
  • 每日OJ题_牛客_字符串分类_哈希+排序_C++_Java
  • 算法Day-7
  • Log4j和SLF4J在Java中打印日志的区别
  • 大厂面试真题-Redis的Cluster模式的smart clent了解吗,怎么初始化的
  • 上传文件到云存储前端报错413 Request Entity Too Large
  • 智能工厂的软件设计 结构映射、类比推理及信念修正
  • AcWing 11 背包问题求方案数
  • MybatisPlus入门(一)MybatisPlus简介
  • 字节流写入文件
  • 理解CPU怎么执行一条指令
  • 【flask web】 Blueprint 蓝图 路由模块化
  • 2、图像的特征