CORBA、IDL、COM和Protocol Buffer

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中的接口定義,包括IDispatch
 import "ocidl.idl"
//1. 定義類型庫
[//方括號中列出 類型庫屬性清單
   uuid(DAD1DA4G-0C17-455C-B8FE-314B56DD10CCD), //類型庫唯一標識符 LIBID
   version(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),//接口的唯一標識符IID
    dual,//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),//組件類的唯一標識符 CLSID
   helpstring("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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章