当前位置: 代码迷 >> 综合 >> CORBA、IDL、COM和Protocol Buffer
  详细解决方案

CORBA、IDL、COM和Protocol Buffer

热度:65   发布时间:2024-01-26 09:41:30.0

1.CORBA

        CORBA是一种标准,是公共对象请求代理结构(Common Object Request Broker Architecture),是由对象管理组织(Object Management Group,缩写为OMG)标准化的一种规范体系。

        对象管理组织是一个国际的非盈利组织,其职责是为应用开发提供一个公共框架,制订工业指南和对象管理规范。OMG是由包括IBM、Sun Microsystem、Apple和美国航空等11家公司在1989年创立的,其最初目的是开发一个分布式面向对象系统的标准。目前,对象管理组织拥有800多名公司成员,包括计算机产业和软件产业的企业,也包括其他产业的成员。

       CORBA的三大核心模块为接口描述语言(或者叫接口定义语言,Interface Definition Language),对象请求代理(Object Request Broker) 和 IIOP标准(网络ORB交换协议, Internet Inter ORB Protocol)。

       CORBA目前可以理解为一个Web Service。CORBA的两个重要特征是:

       1)分布式系统下的跨语言的数据传输;

       2)远程方法的本地调用。

2.IDL

      CORBA的最核心的模块为接口定义语言,即Interface Difinition Language,简写为IDL。IDL是对不同语言之间和不同模块之间传递数据的一个描述。接口定义语言有多种表现形式,最关键是对多种语言之间的传输进行描述,包括接口、唯一性ID标记,方法和属性。

      IDL目前具有多种标准,常见的IDL如下

      1)AIDL: Java-based, for Android; supports local and remote procedure calls, can be accessed from native applications by calling through Java Native Interface(JNI)
2)Apache Thrift: from Apache, originally developed by Facebook
3)Avro IDL: for the Apache Avro system
4)CortoScript: Describe data and/or interfaces for systems that require Semantic interoperability
5)Etch: Cisco's Etch Cross-platform Service Description Language
6)Extensible Data Notation(EDN): Clojuredata format, similar to JSON
7)Franca IDL: the open-source Franca interface definition language
8)IDL specification language: the original Interface Description Language
9)JSONWeb-Service Protocol (JSON-WSP)
10)Microsoft Interface Definition Language(MIDL): the Microsoft extension of OMG IDL to add support for Component             11)Object Model(COM) and Distributed Component Object Model(DCOM)
12)OMG IDL: standardized by Object Management Group, used in CORBA(for DCE/RPC services) and DDS(for data modeling), also selected by the W3C for exposing the DOM of XML, HTML, and CSS documents
13)OpenAPI Specification: a standard for REST interfaces, used by Swaggerand other technologies.
14)Open Service Interface Definitions
15)Protocol Buffers: Google's IDL
16)RESTful Service Description Language (RSDL)
17)Specification Language for Internet Communications Engine(Ice: Slice)
18)Universal Network Objects: OpenOffice.org's component model
19)Web Application Description Language(WADL)
20)Web IDL: can be used to describe interfaces intended for implementing in web browsers
21)Web Services Description Language(WSDL)
22)XCB: X protocol description language for X Window System
23)Cross Platform Interface Description Language (XPIDL): Mozilla's way to specify XPCOM interfaces

3.COM

        COM,即组件对象模型,Component Object Model,是微软倡导的规范。COM标准为MIDL。COM曾经号称继动态库编程之后的又一规范,微软曾大力倡导COM。

       COM的特点如下:

       1)每个COM组件都有唯一的GUID;

       2)旧接口无法抛弃;

       3)客户机不能直接访问vtable,COM接口的vtable唯一要求是表的第一个字段应为IUnknow的指针;

       4)组件通过接口通信,接口一旦发布不可修改;

        COM实现如下:

        1)定义IDL文件;

         2)编译生成接口代理文件、头文件、接口UUID文件和类型库文件;

         3)实现IUnkown接口和自定义接口。

       或者样例如下IDL文件(摘抄于https://www.jianshu.com/p/f4658a78c88c)

      

 //import语句,将引入另一个idl文件中包含的额定义并在本文中使用import "oaidl.idl" //输入文件oaidl.idl中的接口定义,包括IDispatchimport "ocidl.idl"
//1. 定义类型库
[//方括号中列出 类型库属性清单uuid(DAD1DA4G-0C17-455C-B8FE-314B56DD10CCD), //类型库唯一标识符 LIBIDversion(1.0),//版本helpstring("CustomComTypeLibraryLib 1.0  Type Library")
]
//类型库属性清单后紧跟着类型库定义
library CustomComTypeLibraryLib
{//importlib将引入二进制(编译类型库)//所有类型库都要用importlib输入Stdole3d.tlb中定义的基础类型库。用importlib指令输入类型库时,需要保证向客户机提供这个库(要在Com服务器上安装这个库)importlib("stdole32.tlb"); importlib("stdole2.tlb");//--- if the follwing import fails then it means that //--- the type library is not on the system path ,//---you can fix the  problem in two ways://---1.Add it to system wide PATH environment variable//---2. Add it to the executable file list in Developer Studio.importlib("axdb18enu.tlb");//--interface definition
//2. 在类型库中 定义接口ICustomInterfaceOne
//当然你也可以定义多个接口[   //方括号中为属性清单object, //object属性,告诉编译器这是个Com接口定义而不是RPC(远程过程调用)接口定义。uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx),//接口的唯一标识符IIDdual,//dual属性表示客户机有两个不同的方法可以访问这个接口提供的属性和方法,即双接口nonextensible,helpstring("ICustomInterfaceOne interface"),//帮助字符串pointer_default(unique)//该属性指定除参数表中所列特征外所有指针的缺省特征;unique表示指针可以说Null,但不支持别名
]
//属性清单后面是接口定义本身。这里定于ICustomInterfaceOne接口,是从IDispach接口继承来的
//该接口中定义了两个属性 和一个方法interface ICustomInterfaceOne:IDispach
{[propget,id(NameId),helpstring("属性 姓名")] HRESULT Name([out,retval] BSTR* pVal);[propget,id(NameId),helpstring("属性 姓名")] HRESULT Name([in] BSTR newVal);[propget,id(AgeId),helpstring("属性 年龄")] HRESULT Age([out,retval] DOUBLE* pVal);[propget,id(AgeId),helpstring("属性 年龄")] HRESULT Age([in] DOUBLE newVal);HRESULT DoSomething();//方法
}//3. 定义组件类 实现ICustomInterfaceOne
[uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx),//组件类的唯一标识符 CLSIDhelpstring("ICustomInterfaceOne interface"),//帮助字符串
]
coclass ComCustomCoClassOne 
{[default] interface  ICustomInterfaceOne;//组件了指向签名定义的接口ICustomInterfaceOne[source]interface   iAcadObjectEvents;}
}

       然而,COM本身最终却没有流行起来;这除了分布式编程思想的问题意外,更多的原因是微软本身发展的问题;微软没有在互联网时代获得较大的成功。而相应的,微服务思想却流行了起来。

4.Protocol Buffer

      微服务的思想的流行,和互联网公司的发展有关。互联网公司,诸如Google和Facebook,给微服务提供了基础。当然,Google微服务的基础,或者说Google的IDL,即Protocol Buffer有很重要的关联。

        Protocol Buffer是基于二进制编码的树形结构;同时,这种标准的设定,完全遵从了IDL的标准。同时,Protocol Buffer是非常轻量级的,传输效率和编解码效率更高。

        由于Protocol Buffer的这种特点,让Protocol Buffer成为微服务的重要语言。Protocol Buffer的基本学习见本人原创博客(https://blog.csdn.net/wangzhezhilu001/article/details/91457203)。

        基本样例如下:

        

 syntax = "proto3";  package msg;message Image {int32 img_type = 1;int32 img_w = 2;int32 img_h = 3;}

5.评价

1)某种语言或技术的流行,通常和语言本身没有必然关系,仅仅是因为使用者可能认为其更简单,或者某些大型公司在主推该语言;

2)然而,不能认为一种语言或者技术不流行了,就认为该语言或者技术不再重要;一些技术特点会传承下来,例如不同IDL是在OMG的基本思想下不断壮大。

参考文献:

[1]OMG官网,https://www.omg.org/about/index.htm

[2]OMG关于CORBA的介绍,https://www.omg.org/spec/CORBA/3.3/Interfaces/PDF/

[3]Building a Distributed Object System with .NET and J2EE Using IIOP.NET,http://lig-membres.imag.fr/donsez/ujf/GICOM/GICOM_ENS/exemples/dotnet/iiop.net/dist_object_system.asp.html

[4]知乎IDL专栏,https://zhuanlan.zhihu.com/p/96899967

[5]简书关于COM的介绍,https://www.jianshu.com/p/f4658a78c88c

  相关解决方案