COM and DCOM CS 562 February 27, 2001. Motivation Data Analyzer Resource Monitor int compute (…) { } int compute (…) { } Data Analyzer int compute (…)

Slides:



Advertisements
Similar presentations
Component Object Model
Advertisements

Qisheng Hong Yani Mulyani Paul Visokey
COM: A Brief Introduction Dan Berger
Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation.
COM vs. CORBA.
Component Object Model (COM) A short introduction
OOMI A short introduction to Microsoft's Component Object Model (COM)
Remote Object Invocation Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology.
Intro to COM What is it and how do I use it?. Objectives Teach the fundamentals of COM. Understand the reason for using it. Learn to make a simple in-process.
AP 01/01 Asynchronous Calls Standard COM+ model is completely synchronous –Emulates standard procedure calls –Problematic in distributed scenarios with.
Computer Science Lecture 24, page 1 CS677: Distributed OS Today: More Case Studies DCOM Jini.
1 COM/DCOM n Part of Project Presentation (Concept Outline)
AP 01/01 Interface Definition Language Types are problematic: –Weakly typed C language: short / int / long –Architecture-specific data types IDL is a strongly.
1 DirectX CIS 487/587 Bruce R. Maxim UM-Dearborn.
Intro to COM What is it and what can it do for me?
DCOM Technology. What is DCOM? DCOM is just COM with a longer wire DCOM is just COM with a longer wire DCOM extends COM to support communication among.
DCOM Technology Şevket Duran Haşim Sak.
1 Modular Software/ Component Software 2 Modular Software Code developed in modules. Modules can then be linked together to produce finished product/program.
Visual Basic: An Object Oriented Approach 12 – Creating and using ActiveX objects.
CHAPTER 3 The Component Object Model and DirectX © 2008 Cengage Learning EMEA.
CSIS0402 System Architecture Distributed Computing - Middleware Technology (2) K.P. Chow University of Hong Kong.
CSC Proprietary 9/11/2015 2:16:16 AM 008_P2_CSC_white 1.
Smart Reference Proxy Provides additional actions whenever an object is referenced (e.g., counting the number of references to the object) Firewall Proxy.
COM vs. CORBA Computer Science at Azusa Pacific University September 19, 2015 Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department.
Practices of Good Component Design Microsoft Research Asia Advanced Technology.
Threading Models in Visual Basic Language Student Name: Danyu Xu Student ID:98044.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.
Microsoft’s Distributed Component Object Model (DCOM) Jim Ries Updated 10/5/1999 A semi-technical overview.
COM/DCOM Implementation Basics of: Object creation and access Object Reuse Interface referencing.
DCOM-CORBA Comparison Operating Systems II Reference: P. Chung et al., DCOM and CORBA: side by side, step by step,and layer by layer, C++ Report.
OLE / COM Helia / Martti Laiho Sources: MSDN Kraig Brockschmidt: Inside OLE Orfali-Harkey-Erwards: Client/Server Survival Guide.
Introduction to COM and DCOM Organizational Communications and Technologies Prithvi N. Rao H. John Heinz III School of Public Policy and Management Carnegie.
CS 603 DCOM April 5, DCOM – What is it? Start with COM – Component Object Model –Language-independent object interface Add interprocess communication.
COMCOM omponent bject odel After this presentation, you will: Be Able To: Conceptual understanding of COM How it works, What it’s used for Decode Acronyms.
Information Management NTU Interprocess Communication and Middleware.
A COM implementation of the KSpace A ‘Knowledge Space prototype’ by Santhosh CST
OOMI From COM to DCOM.
Ni.com Understanding COM/ActiveX Jeff Paulter Staff Software Engineer Thurs Aug 17 10:15-11:30 a.m., 1:45-3:00 p.m. Ash (10A) Jeff Paulter Staff Software.
Introduction to COM and ActiveX Controls. What is an object? In the Fayad sense of the word.
SE-02 COMPONENTS – WHY? Object-oriented source-level re-use of code requires same source code language. Object-oriented source-level re-use may require.
Implementing COM Objects 主講人:虞台文. Content Types of COM Servers Objects with Single interface – Example  Enumerators Objects with Multiple interfaces.
CS 501: Software Engineering Fall 1999 Lecture 12 System Architecture III Distributed Objects.
OOMI A short introduction to Microsoft's COM From COM to DCOM.
GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.
Eric Tryon Brian Clark Christopher McKeowen. System Architecture The architecture can be broken down to three different basic layers Stub/skeleton layer.
COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.
Seminarium on Component-based Software Engineering Feraaz Imami LIACS – Leiden University Fall 2005 Component Object Model (COM)
Type Information 主講人:虞台文. Content Overview The Type Library Building Type Library Type Library Deployment Loading and Using a Type Library Objects with.
1 Distributed Processing Framework Behind the scenes.
Elements of LCG Architecture Application Architecture Blueprint RTAG 8 th June 2002 P. Mato / CERN.
Component Object Model(COM)
CSE791 - Distributed Objects, Spring 2002
Component Object Model
Component Object Model
Putting the Distributed into COM
Jim Fawcett CSE775 - Distributed Objects Spring 2016
Apartments and COM Threading Models
Microsoft’s Distributed Component Object Model (DCOM)
Interface Definition Language
Out-of-Process Components
C# COM Interoperability Late Binding
COM: A Brief Introduction
COM: A Brief Introduction
Interpreter Style Examples
DCOM-CORBA Comparison
COMPONENTS – WHY? Object-oriented source-level re-use of code requires same source code language. Object-oriented source-level re-use may require understanding.
Out-of-Process Components
Presented By Justas Raslanas
Lecture 7 ATL and Out-of-Process Components
Presentation transcript:

COM and DCOM CS 562 February 27, 2001

Motivation Data Analyzer Resource Monitor int compute (…) { } int compute (…) { } Data Analyzer int compute (…) { } Resource Monitor int compute (…) { } Dynamically Linked Library int compute (…) { }

Distributed Objects Object locator [registry] Communication –Data typing [interface] –Data representation [marshaling] –Synchronous/Asynchronous State persistence System properties: Security, reliability, availability

Architecture ClientServer Client Application Object Implementation Proxy Stub Channel Client Application contains code to access functionality from an object Server may run on same “local” machine, or “remote” machine Registry

COM Basics Component Object Model (COM) COM is a specification that describes: –What an object is –How an object can manage itself over its lifetime –How it tells the outside world what it can do COM is a binary specification, not a language –Java, C++, VB, C

COM object A COM class defines the implementation of one or more interfaces A COM object is instantiated from a COM class A Client application accesses a COM object through interface pointers Client ApplicationCOM object interface pointer

Interfaces List of functions –name –parameters –return type A COM object can implement multiple interfaces Once a COM interface is published it can never change

IUnknown interface IUnknown { HRESULT QueryInterface (REFIID iid, void **ppvObject); ULONG AddRef (); ULONG Release (); } The ancestor of all Interfaces All COM objects must support this interface –Provides reference counting for each interface –Allows clients to locate appropriate interface

Registration of COM objects Interface ID (IID) –128 bits. Statistically “Unique” Excel Worksheet – C System Registry maintains all information –regsvr32.exe

regedit utility

COM IUnknown interface IUnknown { HRESULT QueryInterface ([in] REFIID iid, [out] void **ppvObject); ULONG AddRef (); ULONG Release (); } pInterface pQueryInterface pAddRef pRelease Interface QueryInterface (…) AddRef () Release () Object IUnknown COM Component VTable IUnknown IAnother IOneMore

ISum example pQueryInterface pAddRef pRelease VTable QueryInterface (…) AddRef () Release () Object IUnknown ISum IUnknown COM Component ISum pSum Sum () pInterface

ISum example ULONG MiniCalc::AddRef() { return ++m_cRef; } ULONG MiniCalc ::Release() { if (--m_cRef != 0) return m_cRef; delete this; return 0; } HRESULT MiniCalc::QueryInterface (REFIID riid, void** ppv) { if (riid == IID_IUnknown) { *ppv = (IUnknown*) this; } else if (riid == IID_ISum) { *ppv = (ISum*)this; } else { *ppv = NULL; return E_NOINTERFACE; } AddRef(); return S_OK; } HRESULT MiniCalc ::Sum(int x, int y, int* retval) { *retval = x + y; return S_OK; } class ISum : public IUnknown { public: virtual HRESULT Sum (int x, int y, int *retval) = 0; }; class MiniCalc : public ISum { public: // IUnknown ULONG AddRef(); ULONG Release(); HRESULT QueryInterface(REFIID iid, void** ppv); // ISum HRESULT Sum(int x, int y, int* retval); MiniCalc() : m_cRef(1) { } ~MiniCalc () {} private: ULONG m_cRef; };

Implementing Interfaces in C++ Multiple Inheritance Containment Aggregation IUnknown COM Component IMultiplyISum [ object, uuid( ) ] interface ISum : IUnknown { HRESULT Sum(int x, int y, [out, retval] int* retval); } [ object, uuid( ) ] interface IMultiply : IUnknown { HRESULT Multiply(int x, int y, [out, retval] int* retval); }

Multiple Inheritance class ISum : public IUnknown { public: virtual HRESULT Sum (int x, int y, int *retval) = 0; }; class IMultiply : public IUnknown { public: virtual HRESULT Multiply (int x, int y, int *retval) = 0; }; class MandS : public ISum, IMultiply { public: // IUnknown HRESULT QueryInterface(REFIID tiid, void **ppvObject); ULONG AddRef(); ULONG Release(); // Isum HRESULT Sum (int x, int y, int *retval); // IMultiply HRESULT Multiply (int x, int y, int *retval); private: ULONG m_cRefs; } MandS() : m_cRef(1) {} ~MandS() {} ULONG MandS ::AddRef() { return ++m_cRef; } ULONG MandS ::Release() { if(--m_cRef != 0) return m_cRef; delete this; return 0; } HRESULT MandS::QueryInterface(REFIID riid, void** ppv) { if (riid == IID_IUnknown) { *ppv = (IUnknown *) this; } else if (riid == IID_ISum) { *ppv = (Isum *) this; } else if (riid == IID_IMultiply) { *ppv = (Imultiply *) this; } else { *ppv = NULL; return E_NOINTERFACE; } AddRef(); return S_OK; } Reference Counting on Object Level! Not on interface Level

const CLSID CLSID_Container = {0x ,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}}; class Container : public IMultiply, ISum { public: // IUnknown HRESULT QueryInterface(REFIID tiid, void **ppvObject); ULONG AddRef(); ULONG Release(); // IMultiply HRESULT Multiply (int x, int y, int *retval); // ISum HRESULT Sum (int x, int y, int *retval); HResult Init(); private: ULONG m_cRef; ISum *m_pSum; } Container::Container() : m_cRef(1), m_pSum(NULL) {} Container::~Container() { m_pSum->Release(); } HRESULT Container::Init() { return CoCreateInstance(CLSID_Container, NULL, CLSCTX_INPROC_SERVER, IID_ISum, (void**)&m_pSum); } HRESULT Container::Sum(int x, int y, int* retval) { return m_pSum->Sum(x, y, retval); } HRESULT Container::Multiply(int x, int y, int* retval) { *retval = x * y; return S_OK; } ULONG Container::AddRef() { return ++m_cRef; } ULONG Container::Release() { if (--m_cRef != 0) return m_cRef; delete this; return 0; } Containment IUnknown ISumIMultiply ISum

const CLSID CLSID_ Aggregator = {0x ,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}}; class Aggregator : public IMultiply { public: // IUnknown HRESULT QueryInterface(REFIID tiid, void **ppvObject); ULONG AddRef(); ULONG Release(); // IMultiply HRESULT Multiply (int x, int y, int *retval); Aggregator(); ~Aggregator(); HResult Init(); private: ULONG m_cRef; IUnknown* m_pUnknownInner; } Aggregator::Aggregator() : m_cRef(1) {} Aggregator::~Aggregator() { m_pUnknownInner->Release(); } HRESULT Aggregator::Init() { return CoCreateInstance(CLSID_Aggregator, (IUnknown*)this, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&m_pUnknownInner); } HRESULT Aggregator ::Sum(int x, int y, int* retval) { return m_pSum->Sum(x, y, retval); } HRESULT Aggregator ::Multiply(int x, int y, int* retval) { *retval = x * y; return S_OK; } Aggregation HRESULT CAggregator::QueryInterface(REFIID riid, void** ppv) { if (riid == IID_IUnknown) { *ppv = (IUnknown*)this; } else if (riid == IID_ISum) { return m_pUnknownInner->QueryInterface(riid, ppv); } else if(riid == IID_IMultiply) { *ppv = (IMultiply*)this; } else { *ppv = NULL; return E_NOINTERFACE; } AddRef(); return S_OK; } IUnknown IMultiplyISum IUnknown Knows ISum and IMultiply

Reference counts A COM object must remember which of its interfaces are being used –once refcount = 0, interface is no longer being used –once all refcounts = 0 for all interfaces supported by an object, it can be shutdown Client code must be disciplined –when making a copy of an interface pointer, must manually increment refcount –when finished with an interface, must manually decrement refcount

Accessing COM objects const CLSID CLSID_Container = {0x ,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}}; main () { IMultiply* pMultiply; CoInitialize(NULL); // Get COM started CoCreateInstance(CLSID_Container, // [in]RCLSID NULL,// [in]Outer Object (if any) CLSCTX_INPROC_SERVER,// [in]Access Context IID_IMultiply, // [in] RIID (of desired interface) (void**) &pMultiply);// [out] Interface Pointer int multiply; hr = pMultiply->Multiply(4, 3, &multiply); if(SUCCEEDED(hr)) { // process }

Accessing interfaces using interface pointer // use existing interface pointer to locate other interface pointer ISum* pSum; pMultiply->QueryInterface(IID_ISum, (void**) &pSum); int sum; hr = pSum->Sum(4, 3, &sum); if(SUCCEEDED(hr)) { // process } hr = pMultiply->Release(); hr = pSum->Release(); CoUninitialize(); } Responsibility of QueryInterface

Class Factory const CLSID CLSID_ Factory = {0x ,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}}; class CFactory : public IClassFactory { public: // IUnknown HRESULT QueryInterface(REFIID tiid, void **ppvObject); ULONG AddRef(); ULONG Release(); // IClassFactory HRESULT CreateInstance(IUnknown *pUnknownOuter, REFIID iid, void** ppv); HRESULT LockServer(BOOL bLock); CFactory() : m_cRef(1) { } ~CFactory() { } private: ULONG m_cRef; }; ULONG CFactory::AddRef() { return ++m_cRef; } ULONG CFactory::Release() { if (--m_cRef != 0) return m_cRef; delete this; return 0; } HRESULT CFactory::QueryInterface(REFIID iid, void** ppv) { if ((iid == IID_IUnknown) || (iid == IID_IClassFactory)) { *ppv = (IClassFactory *) this; } else { *ppv = NULL; return E_NOINTERFACE; } AddRef(); return S_OK; } HRESULT CFactory::CreateInstance(IUnknown *pUnknownOuter, REFIID iid, void** ppv) { if (pUnknownOuter != NULL) return CLASS_E_NOAGGREGATION; MiniCalc *pMiniCalc = new MiniCalc; if (pMiniCalc == NULL) return E_OUTOFMEMORY; // QueryInterface probably for IID_IUNKNOWN HRESULT hr = pMiniCalc ->QueryInterface(iid, ppv); pMiniCalc ->Release(); return hr; }

Factory example // { } const CLSID CLSID_Factory = {0x ,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}}; void main() { HRESULT hr = CoInitialize(NULL); IUnknown* pUnknown; ISum* pSum; IClassFactory* pClassFactory; hr = CoGetClassObject(CLSID_Factory, CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory, (void**)&pClassFactory); pClassFactory->CreateInstance(NULL, IID_IUnknown, (void**)&pUnknown); pClassFactory->Release(); hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum); hr = pUnknown->Release(); int sum; hr = pSum->Sum(2, 3, &sum); if (SUCCEEDED(hr)) cout << "Client: Calling Sum(2, 3) = " << sum << endl; hr = pSum->Release(); CoUninitialize(); } IClassFactory ClassFactory IUnknown pCreateInstance pLockServer IUnknown creates Object IUnknown ISum IUnknown pAdd Add

Object Counts long g_cComponents = 0; long g_cServerLocks = 0; Container::Container() : m_cRef(1), m_pSum(NULL) { g_cComponents++; } Container::~Container() { g_cComponents--; } HRESULT CFactory::LockServer(BOOL bLock) { if (bLock) g_cServerLocks++; else g_cServerLocks--; return S_OK; } HRESULT DllCanUnloadNow() { if (g_cServerLocks == 0 && g_cComponents == 0) return S_OK; else return S_FALSE; } HRESULT DllGetClassObject(REFCLSID clsid, REFIID iid, void** ppv) { if (clsid != CLSID_Aggregate) return CLASS_E_CLASSNOTAVAILABLE; CFactory* pFactory = new CFactory; if (pFactory == NULL) return E_OUTOFMEMORY; // QueryInterface probably for IClassFactory HRESULT hr = pFactory->QueryInterface(iid, ppv); pFactory->Release(); return hr; } HRESULT DllRegisterServer() { return RegisterServer("aggregate.dll", CLSID_Container, "Aggregate", "Component.Aggregate", "Component.Aggregate.1", NULL); } HRESULT DllUnregisterServer() { return UnregisterServer(CLSID_Aggregate, "Component.Aggregate", "Component.Aggregate.1"); }

Context for COM object INPROC_SERVER INPROC_HANDLER LOCAL_SERVER REMOTE_SERVER

INPROC_SERVER Dynamically Linked Library (DLL) COM object executes in same process space IMultiply* pMultiply; CoCreateInstance(CLSID_Container, [in]RCLSID NULL,[in]Outer Object CLSCTX_INPROC_SERVER,[in]ClsContext IID_IMultiply, [in] RIID (void**)&pMultiply);[out] Interface Pointer

INPROC_HANDLER DLL with custom marshaling of data

LOCAL_SERVER Executable (EXE) Dynamically Linked Library loaded into a surrogate process

REMOTE_SERVER Executable (EXE) on a remote machine Dynamically Linked Library loaded into a surrogate process on a remote machine

The Big Picture Client Application In-Process Server In-Process Object COM Local Object Proxy Remote Object Proxy Client Process Local Server Process Remote Server Process COM Stub COM Stub Local Server Remote Server Local Object Remote Object Remote Machine

Under the Hood Page 115 from DCOM