Presentation is loading. Please wait.

Presentation is loading. Please wait.

COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Similar presentations


Presentation on theme: "COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General."— Presentation transcript:

1 COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie

2 Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General approach of dealing with components  Microsoft’s solution – COM/DCOM Component Object Model Distributed Component Object Model

3 Challenges for Software Industry  Applications are large and complex  Applications are not modular  Applications are not easily integrated  Operating systems have similar problems

4 General Approach of Dealing with Challenges Client API Vendor #1’s Component Vendor #2’s Component

5 Problems with the Traditional Approach  The evolution of an API is a problem.  Advertising and maintaining different versions of the API can be problematic.  Enabling components to communicate with each other is challenging.  The programming language to create components greatly impacts the component communication through an API.

6 Microsoft’s Solution – COM and DCOM  Component Object Model (COM)  Distributed Component Object Model (DCOM)

7 Component Software  A component is reusable piece of software in binary form that can be plugged into other components from other vendors with relatively little effort.  Example – spell checker

8 Features of Component Software  Reusable software components  Components in binary form  Components easy to combine

9 What’s COM  COM is a standard for the interaction of binary objects.  COM is also an integration technology.  Objects developed independent  Provide standard model

10 What is COM? (continued) Client Application COM: Established Connection Server Application Object

11 The Goals of COM?  By providing a binary and network standard, COM enables interoperability among applications of different vendors.  Object-based programming  Promote interoperability  Components cooperate  Allow applications to connect as software objects.  Provide operation

12 The Goals of COM For example:  Word processor Spreadsheet Mainframe database  Objects support a predefined standard interface for data exchange

13 The Goals of COM  Because COM is a binary standard, objects can be implemented in a number of different programming languages.  Objects can be used from clients that are written using completely different programming languages

14 The Goals of COM  Vendor independence ODBC driver Lots of effort to transfer code COM objects export only interface Easily upgrade without recompiling

15 What is DCOM?  Extension of COM  Client and server on different computers

16 COM Objects in Same Processes From Same Machine

17 COM Objects in Different Processes From Same Machine

18 How DCOM Establishes Connections among COM Objects From Different Machines

19 Nice Features of DCOM  Location independence Hide the location The way to connect and call methods is identical.  Language neutrality Developers can choose the languages Take advantage of free threading.  Scalability  Fault tolerance  Easy deployment

20 How COM/DCOM works  Objects and interfaces  The COM Client/Server Model

21 Object and Interface Interfaces and C++ Class Interface Definitions: IDL How an Interface Works Object Picture

22 How An Interface Works Interface Pointer pointer Pointer to function1 Pointer to function2 Pointer to function3 …… Interface function table Function1(..) { … } Function2(..) { … } Function3(..) { … } …

23 Object Picture A and B are interfaces The object implements each member function of the interface and provides pointers to those functions to COM. COM then makes those functions available to any client. object A B

24 The COM Client/Server Model Relationship between client, COM, and server COM Object and Class Identifiers COM Clients COM Servers Location Transparency

25 Relationship between client, COM, and server Client Application COM Server Object (1) “Create Object” (2) Locate implementation (3) Get object interface pointer, return to Client (4) Call interface members

26 COM Object and Class Identifiers A COM class – A particular implementation of certain interfaces – Machine code – to be used by different applications A COM object – Identified by a unique128-bit CLSID that associates an object class A CLSID – GUID like an interface identifier

27 COM Clients A COM Client asks COM to instantiate objects in two way: – To call the COM function CoCreateInstance – Use a class factory To manufacture an object of a class

28 COM Clients Client Server Class Factory Object (1)“Create An Object” (2)Manufacture object (3)Return new interface pointer to client

29 COM Server Two basic kinds of object servers – Dynamic Link library (DLL) Based The server is implemented in a module that can be loaded into and will execute within, a client’s address space – EXE Based The server is implemented as a stand-alone executable module

30 COM Servers Server Module Server Object Class Factory: creates Object IClassFactory Object Interfaces Implementation identical for any module Implementation differs for DLLs and EXES Exposure for class factory Unloading Mechanism

31 COM Server Server Flavors: In-Process Server – A server can be loaded into the client’s process and serves “in- process object’ Local Server – A sever runs in a separate process on the same machine as the client and serves “local object” Remote Server – A server runs on a separate machine and therefore always runs in another process as well to serve “remote objects”

32 Location Transparency A single programming model – Dealing with in-process or remote objects is transparent and identical to dealing with in-process objects

33 Location Transparency Client Application In-process server In-process object COM Local Object Proxy Remot Object proxy Local Server Process COM Stub Local Server Local Object Remote Machine Remote Server Process Remote Server Remote Object COM Stub

34 Architecture for Distributed objects Client proxy RPC Runtime Transport stub Object Transport channel COM Library Process Boundary

35 COM Library COM is a specification for how objects and their clients interact through the binary standard of interfaces. COM is also an implementation contained “COM Library” (such as DLL on Microsoft Windows)

36 COM Library (continued) COM Library includes: A small number of fundamental API functions: facilitate the creation of COM applications. Implementation locator service: class identifier  server? location? Transparent remote procedure calls Memory management

37 COM as a Foundation Binary standard of interface: Key to COM’s extensible architecture Foundation upon which is build the rest of and the other systems(OLE etc) 1.COM infrastruction 2.OLE

38 1) COM Infrastruction Persistent Storage: A set of interface and an implementation of those interfaces that create structured storage, otherwise known as a “file system within a file” Persistent, Intelligent Names (Monikers): The ability to give a specific instantiation of an object a particular name that would allow a client to reconnect to that exact same object instance with the same state at a later time. Uniform Data Transfer : Standard interfaces through which data is exchanged between a client and an object and through which a clent can ask an object to send notification in case of data change

39 COM is built in progressively higher level technologies that depend upon lower level technologies.

40 2) OLE Microsoft’s OLE technology: a collection of additional higher-level technologies that build upon COM and its infrastruction. OLE 2 –includes mostly user-interface oriented features based on usability, application integration, and automation of tasks. –All of these features are implemented by means of specific interfaces on different objects and defined sequences of operation in both clients and servers and their relationships and dependencies on the lower level infrastructure of COM

41 OLE builds its features on COM.

42 OLE(Continued) Drag & Drop : The ability to exchange data by picking up a selection with the mouse and visibly dropping it onto another window. Automation : The ability to create “programmable” applications that can be driven externally from a script running in another application to automate common end user tasks. Automation enables cross-application macro programming. Compound Documents : The ability to embed or link information in a central document encouraging a more document-centric user interface.

43 How to create a Client 1.Initializing the COM Libraries 2.Getting the CLSID of an Object 3.Creating an instance of an Object 4.Using a COM Object 5.Uninitializing the COM Libraries

44 1) Initializing the COM Libraries { HRESULT hr; hr = CoInitialize(NULL); if (FAILED(hr)) return FALSE … }

45 2) Getting the CLSID of an Object CLSIDs: a unique class name with a 128-bit number ProgIDs: CLSID  ProgIDs (readable) { … CLSID clsid; hr = CLSIDFromProgID(OLESTR(“Simple.Object”), &clsid); if (FAILED(hr)) return FALSE; … }

46 3) Creating an instance of an Object { … IStream * pStream; hr = CoCreateInstance( clsid, NULL, CLSCTX_LOCAL_SERVER, IID_Istream, (LPVOID *) &pStream); … }

47 4) Using a COM Object { … if (SUCCEEDED(hr)) { //Use the interface pointer pStream->Read(…); pStream->Release(); … }

48 5) Uninitializing the COM Libraries { … CoUninitialize(); … }

49 How to create a COM Object Deriving a C++ Class from an Interface Implementing the Methods of an Interface Controlling the life time of a COM Object

50 Deriving a C++ Class from an Interface In C++, interface is defined as a structure that contains only pure virtual functions. Class Csimple : public Istream { // IUnknown methods // IStream methods };

51 Implementing the Methods of an Interface Examples: AddRef and Release Methods AddRef: ULONG _stdcall CSimpleObject::AddRef(void) { return ++m_cRef; //return InterlockedIncrement(&m_cRef); }

52 Implementing the Methods of an Interface (continued) Release ULONG _stdcall CSimpleObject::Release(void) { if (0 == --m_cRef) { delete this; return 0; } return m_cRef; }

53 Controlling the life time of a COM Object 1.Simplest strategy (Object server – one object): object – central reference count if (reference count == 0) delete itself 2.COM object server – more than one object Reference counter of all object == 0 Server shut down

54 Costs and Limitations Low cost development tools from Microsoft (such as VC++ and VB) Construction of clients and servers is straightforward Initial price for COM/DCOM is low on Windows platforms. Unclear about other platforms Beyond basic costs to produce the technology, any serious software development using COM/DCOM requires substantial programmer expertise. However, Microsoft has strong organization to assist individuals developing COM clients and objects

55 References Book: Mastering COM Development Web site: http://www.sei.cmu.edu/str/descriptions/com.html http://www.microsoft.com/com/resources/specs.asp http://www.microsoft.com/com/tech/DCOM.asp

56 Questions?


Download ppt "COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General."

Similar presentations


Ads by Google