com / dcom xiaolan lu mingzhen wang dong xie. why com / dcom? challenges facing the software...
TRANSCRIPT
COM / DCOM
Xiaolan Lu
Mingzhen Wang
Dong Xie
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
Challenges for Software Industry
Applications are large and complex Applications are not modular Applications are not easily integrated Operating systems have similar
problems
General Approach of Dealing with Challenges
Client
API
Vendor #1’s Component
Vendor #2’s Component
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.
Microsoft’s Solution – COM and DCOM
Component Object Model (COM) Distributed Component Object Model
(DCOM)
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
Features of Component Software
Reusable software components Components in binary form Components easy to combine
What’s COM
COM is a standard for the interaction of binary objects.
COM is also an integration technology.Objects developed independentProvide standard model
What is COM? (continued)
Client Application
COM:EstablishedConnection
ServerApplication
Object
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
The Goals of COM
For example: Word processor
Spreadsheet
Mainframe database Objects support a predefined standard interface
for data exchange
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
The Goals of COM
Vendor independence
• ODBC driver• Lots of effort to transfer code• COM objects export only interface• Easily upgrade without recompiling
What is DCOM?
Extension of COM Client and server on different computers
COM Objects in Same Processes From Same
Machine
COM Objects in Different Processes From Same
Machine
How DCOM Establishes Connections among COM Objects From Different
Machines
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
How COM/DCOM works Objects and interfaces The COM Client/Server Model
Object and InterfaceObject and Interface
Interfaces and C++ Class Interface Definitions: IDL How an Interface Works Object Picture
How An Interface WorksHow An Interface Works
Interface Pointer
pointer Pointer to function1
Pointer to function2
Pointer to function3
……
Interface function tableFunction1(..) { … }
Function2(..) { … }
Function3(..) { … }
…
Object PictureObject PictureA 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.
objectA
B
The COM Client/Server ModelThe COM Client/Server Model
Relationship between client, COM, and server COM Object and Class Identifiers COM Clients COM Servers Location Transparency
Relationship between client, COM, and Relationship between client, COM, and serverserver
ClientApplication
COM
Server
Object
(1) “Create Object”
(2) Locate implementation
(3) Get object interface pointer, return to Client
(4) Call interface members
COM Object and Class IdentifiersCOM 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
COM ClientsCOM 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
COM ClientsCOM Clients
Client
Server
Class Factory
Object
(1)“Create An Object”
(2)Manufacture object(3)Return new
interface pointer to client
COM ServerCOM 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
COM ServersCOM Servers
Server ModuleServer
Object
Class Factory:creates Object
IClassFactory
Object Interfaces Implementation identical for any module
Implementation differs for DLLs and EXESExposure for
class factory
Unloading Mechanism
COM ServerCOM 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”
Location TransparencyLocation Transparency
A single programming model– Dealing with in-process or remote objects is transparent
and identical to dealing with in-process objects
Location Transparency Location Transparency
ClientApplication
In-processserver
In-processobject
COM
LocalObjectProxy
RemotObjectproxy
Local Server Process
COM
Stub
Local Server
LocalObject
Remote Machine
Remote Server Process
Remote Server
RemoteObject
COM
Stub
Architecture for Distributed objectsArchitecture for Distributed objects
Client
proxy
RPC Runtime RPC Runtime
Transport
stub
Object
Transport
channel channel
COM Library COM Library
Process Boundary
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)
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
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 infrastruction2. OLE
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
The Component Object Model and Component Objects
Intelligent NamesPersistent Storage
Uniform Data Transfer
COM is built in progressively higher level technologies thatdepend upon lower level technologies.
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
The Component Object Model and Component Objects
Intelligent Names
Automation
Persistent Storage
Uniform Data Transfer
Linking
Embedding
In-Place Activation(Visual Editing)
CompoundDocuments
Drag & Drop
COM
OLE
OLE builds its features on COM.
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.
How to create a Client
1. Initializing the COM Libraries2. Getting the CLSID of an Object3. Creating an instance of an Object4. Using a COM Object5. Uninitializing the COM Libraries
1) Initializing the COM Libraries
{HRESULT hr;hr = CoInitialize(NULL);if (FAILED(hr))
return FALSE…
}
2) Getting the CLSID of an Object
CLSIDs: a unique class name with a 128-bit numberProgIDs: CLSID ProgIDs (readable)
{…CLSID clsid;hr = CLSIDFromProgID(OLESTR(“Simple.Object”), &clsid);if (FAILED(hr))
return FALSE;…
}
3) Creating an instance of an Object
{…IStream * pStream;hr = CoCreateInstance(
clsid,NULL,CLSCTX_LOCAL_SERVER,IID_Istream,(LPVOID *) &pStream);
…}
4) Using a COM Object
{…if (SUCCEEDED(hr)){ //Use the interface pointer
pStream->Read(…);pStream->Release();
…}
5) Uninitializing the COM Libraries
{…CoUninitialize();…
}
How to create a COM Object
Deriving a C++ Class from an InterfaceImplementing the Methods of an InterfaceControlling the life time of a COM Object
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
};
Implementing the Methods of an Interface
Examples: AddRef and Release MethodsAddRef:ULONG _stdcall CSimpleObject::AddRef(void){ return ++m_cRef; //return InterlockedIncrement(&m_cRef);}
Implementing the Methods of an Interface (continued)
ReleaseULONG _stdcall CSimpleObject::Release(void){
if (0 == --m_cRef){ delete this; return 0;}
return m_cRef;}
Controlling the life time of a COM Object
1. Simplest strategy (Object server – one object): object – central reference countif (reference count == 0) delete itself
2. COM object server – more than one object Reference counter of all object == 0 Server
shut down
Costs and LimitationsLow cost development tools from Microsoft (such as VC++ and VB)Construction of clients and servers is straightforwardInitial price for COM/DCOM is low on Windows platforms. Unclear about other platformsBeyond 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
References
Book:• Mastering COM DevelopmentWeb site:http://www.sei.cmu.edu/str/descriptions/com.htmlhttp://www.microsoft.com/com/resources/specs.asphttp://www.microsoft.com/com/tech/DCOM.asp
Questions?Questions?