280 likes | 392 Views
Course structure. 1: Component software principles 2: Javabeans 3: COM (DCOM/COM+/OLE/ActiveX) 4: CORBA, more ActiveX, comparison. COM-based technologies. ActiveX [set of COM-based technologies]. OLE – Object Linking and Embedding [standards for compound documents].
E N D
Course structure 1: Component software principles 2: Javabeans 3: COM (DCOM/COM+/OLE/ActiveX) 4: CORBA, more ActiveX, comparison MIT IAP 1999
COM-based technologies ActiveX [set of COM-based technologies] OLE – Object Linking and Embedding [standards for compound documents] COM – Component Object Model [open specification] MIT IAP 1999
COM • Open component specification • Language/platform independent • IS NOT just library, class library, or API MIT IAP 1999
COM components • In Win32: either EXE (server) or DLL (in-process server) • Language independent • Can be shipped in binary form • Can be upgraded without breaking old clients • Can be transparently relocated on network MIT IAP 1999
Object Function1(...) { ... } Function2(...) { ... } Function3(...) { ... } ... COM Interface • COM deals with interface pointers • Interface is implemented as a virtual function table Interface Pointer Interface Pointer Interface Function Table Pointer to Function1 pointer Pointer to Function2 Pointer to Function3 ... MIT IAP 1999
Interface names • For people: ISomething – may not be unique • For software: 128-bit IID or GUID (globally unique identifier) generated based on time and network address by UUIDGEN utility MIT IAP 1999
IUnknown • All COM interfaces inherit from IUnknown: • QueryInterface - finds object’s interface by IID, and returns pointer to it • AddRef, Release – reference counting MIT IAP 1999
Reference Count • Indicates how many clients use the same object • Increments when object passes pointer to one of its interfaces • Each client must call Release after it finishes using object interface • Object may destroy itself when reference count drops to 0 MIT IAP 1999
COM Classes • Every COM object is an instance of a class • Class can be assigned a GUID called a class identifier (CLSID) • A class identifies the implementation of a group of interfaces • Class names and CLSIDs are in a database. Win32 uses the registry to save them. MIT IAP 1999
COM Library • Group of functions that supply basic services for clients and objects • Locates and starts servers for requested classes • CoCreateInstance, CoCreateInstanceEx, CoGetClassObject, CoRegisterClassObject MIT IAP 1999
Server (1) “Create an Object” Client Class Factory (3) Return new (2) Manufacture interface pointer Object to client Object Class Factory • IClassFactory – interface for efficient generation of multiple instances of a class • Methods: CreateInstance, LockServer MIT IAP 1999
Containment Aggregation knows IUnknown IUnknown knows A, B, and C A, B, and C External External Interfaces Interfaces IUnknown IUnknown controls Inner controls Inner Outer Object uses Inner Object Object lifetime Object lifetime Inner Object’s C delegates IUnknown implementation calls to Outer Object as any client. Inner Object : Inner Object : Contained inside Contained inside Inner Object’s Outer Object Outer Object C exposed directly from Outer Object Object Reusability Outer Object Outer Object A A B B C C C MIT IAP 1999
In-Process Object Local Stub Object Client Application Local Object Proxy Remote Object Proxy Remote Stub Object Distributed COM Client Process Local Server Process In-Process Server COM Local Server RPC Remote Machine COM Remote Server Process RPC COM Remote Server MIT IAP 1999
Dispatch Interface • IDispatch originally designed for Visual Basic • Invoke, GetIDsOfNames, GetTypeInfo, GetTypeInfoCount • Late binding MIT IAP 1999
Dual Interfaces • Dispinterface that includes virtual function table to access its functions • Supports both late and early binding • Good for all languages MIT IAP 1999
Interface Definition Language (IDL) • Example [ object, uuid(a817e7a2-43fa-11d0-9e44-00aa00b6770a), dual, helpstring("IComponentRegistrar Interface"), pointer_default(unique) ] interface IComponentRegistrar : IDispatch { [id(1)] HRESULT Attach([in] BSTR bstrPath); [id(2)] HRESULT RegisterAll(); [id(3)] HRESULT UnregisterAll(); [id(4)] HRESULT GetComponents([out] SAFEARRAY(BSTR)* pbstrCLSIDs, [out] SAFEARRAY(BSTR)* pbstrDescriptions); [id(5)] HRESULT RegisterComponent([in] BSTR bstrCLSID); [id(6)] HRESULT UnregisterComponent([in] BSTR bstrCLSID); } MIT IAP 1999
Interface Definition Language (IDL) • Type libraries (TLB) • ITypeLib, ITypeInfo • Proxies and Stubs • MIDL – IDL compiler MIT IAP 1999
Persistence • IStorage = file system • IStream = file • IPersist* interfaces MIT IAP 1999
Monikers • names specific object instance • knows how to create and initialize its object • Methods: BindToObject, BindToStorage, Reduce, ComposeWith, IsRunning • Composite monikers MIT IAP 1999
Uniform Data Transfer • Single scheme for moving data between applications • Clipbord, drag and drop • IDataObjectInterface: GetData, SetData, … • IAdviseSink MIT IAP 1999
Connectable object Client IConnectionPointContainer IConnectionPoint Sink Sink Outgoing interface IConnectionPoint Sink Outgoing interface Sink Connectable Objects MIT IAP 1999
Threading Models • Single • Apartment • Free • Mixed (Apartment or Free) MIT IAP 1999
OLE Compound Documents • Containers and servers • Image caching • IOleObject, IOleClientSite, IOleCache, … MIT IAP 1999
ActiveX controls and containers Container and control interfaces: IOleInPlaceActiveObject ActiveX control Control container IOleInPlaceUIWindow IOleInPlaceObject IOleInPlaceFrame IOleObject IOleInPlaceSite IDataObject IOleInClientSite IViewObject2 IAdviseSink IRunnableObject IOleCache2 IPersistStorage MIT IAP 1999
Methods, properties, events • Methods – just methods • Properties – GetProperty/SetProperty or Property methods: HRESULT Source([out, retval] BSTR* path); HRESULT Source([in] BSTR path); // OR HRESULT GetSource([out, retval] BSTR* path); HRESULT SetSource([in] BSTR lpszNewValue); • Events – methods control invokes on its client (container) MIT IAP 1999
ActiveX in html • ActiveX components can be placed on a web page • Web browser can automatically install missing components < OBJECT ID=“ctlFind” type=“application/x-oleobject” CLASSID=“CLSID:D3E12F4B-0795-11d2-91CC-00C04FA31C90” codebase="http://fdl.msn.com/public/investor/v6//investor.cab#version=6,1998,1031,3" width=72 height=19 align=middle > <param name="ServerRoot" value="http://investor.msn.com"> <param name="PageURL" value="/charts/charting.asp"> <param name="InvType" value="1"> </OBJECT> MIT IAP 1999
Versioning • Immutable interfaces • Multiple interfaces • no merging of interfaces • Emulate other class: CoTreatAsClass • Generic services MIT IAP 1999
COM object multiple interfaces interface inheritance polymorphism through multiple interfaces multiple implementing objects no persistent identity: e.g. monikers C++ object multiple inheritance polymorphism through public inheritance single implementing object fragile base class problem COM object vs. C++ object MIT IAP 1999