Component Object Model - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Component Object Model

Description:

Explain how COM tackles the problems. Explain how Interfaces are used. GUIDs ... To set up connections between components. To manage across interaction networks. DCOM ... – PowerPoint PPT presentation

Number of Views:1058
Avg rating:3.0/5.0
Slides: 26
Provided by: chris520
Category:
Tags: component | dcom | model | object | ole

less

Transcript and Presenter's Notes

Title: Component Object Model


1
Component Object Model
  • Outline the goals of COM
  • Explain how COM tackles the problems
  • Explain how Interfaces are used
  • GUIDs
  • Location independence
  • Versioning
  • Evaluate if COM achieves its goals

2
What is COM?
  • Common Object Model
  • System architecture for using components
  • Problems
  • Co-operation Communication between
  • components from different developers
  • components written in different languages
  • Transparent cross-process interaction
  • Versioning
  • upgrading a component without ill effects
  • High performance
  • little overhead for in-process components

3
COM Fundamentals
  • A binary standard
  • Allowing function calls between components.
  • Strongly-typed interfaces to group functions
  • A base interface (IUnknown) providing
  • A way to obtain other related interfaces
  • Reference counting to manage component lifetime
  • Unique ids for components and interfaces
  • Globally Unique Identifiers (GUID).
  • A "component loader" to
  • set up component interactions and
  • manage interactions across processes and networks

4
What is an Interface? 1
  • A contract
  • A definition of methods (header)
  • Name
  • Parameters
  • Result
  • A fully abstract class (more or less)
  • When I ask for a pointer to an interface, you can
    give me any class that satisfies the interface

5
Using COM
The unique class identifier of a word-processor
application
A factory method that creates an instance of a
class
  • IDocument pDoc NULL
  • HRESULT hr CoCreateInstance(CLSID_WORDPROC, 0,
    CLSCTX_ALL, IID_IDocument, (void)pDoc)
  • if (SUCCEEDED(hr))
  • ISpellChk pSpell NULL
  • hr pDoc-gtQueryInterface(IID_ ISpellChk,
    (void)pSpell)
  • if (SUCCEEDED(hr))
  • hr pSpell-gtCheckSpelling("the cat st on
    the mat)
  • if (SUCCEEDED(hr))
  • hr pSpell-gtGetBadWords(pBadWordList)
  • pSpell-gtRelease()
  • pDoc-gtRelease()
  • // use bad word list
  • pBadWordList-gtRelease()

The unique identifier of a document interface
6
Binary Standard
  • For any given platform, all interfaces use a
    standard way to lay out and use virtual method
    tables (vtables)
  • Any language able to call functions via pointers
    can make components
  • Each type of interface has its own vtable.
  • One vtable per class lowers overhead

7
What must be in the standard?
  • To allow communication across languages, the
    standard defines
  • Calling convention
  • Parameter passing convention
  • Order, clearing stack
  • Returning results
  • Representation of data types
  • Size, layout, encoding
  • Similar definitions are part of the definition of
    Java , why?

8
COM Object Virtual Method Tables
IUnknown
Interface implemented by all COM objects

MyPara1

VMT
IParagraph

QueryInterface()
MyPara2
AddRef()

Release()
PrintParagraph()
Data probably stored here
MySpeller
ISpellCheck

QueryInterface()
AddRef()


Release()

SpellCheck(char txt)

Interface Pointers
1 VMT per class
Methods



9
Objects and components
IUnknown is important Remember it
  • COM Object (component object)
  • Compiled code providing a service
  • a server
  • Distinct from source-code OO programming
  • Types of server
  • "in-process," "local," "remote"
  • Must support a base interface IUnknown
  • May define other interfaces,
  • to provide access to components service

10
Encapsulation information hiding
  • A Component's data is only accessible through
    interfaces.
  • Also allows for transparent remote operation via
    proxy objects.

COM Object
11
What is an Interface? 2
  • A set of related functions
  • Providing a well-defined service
  • A strongly-typed contract between components
  • Definition of expected behaviour and
    responsibilities. e.g. drag-and-drop support
  • COM objects can implement many interfaces.
  • Interfaces are strongly typed
  • With a globally unique ID (GUID)
  • Interfaces are immutable must not change
  • A new version has a new identifier.

12
Interface Approach Benefits 1
  • Functionality of clients or servers can evolve
  • An object can make new interfaces available to
    new clients while retaining binary compatibility
    with existing client code.
  • Revision without recompilation
  • Robust to version changes
  • COM interfaces are immutable
  • Components can support old interfaces when adding
    new ones.
  • This gives backward compatibility as components
    are upgraded.
  • Fast and simple object interaction.

13
Interface Approach Benefits 2
  • Interface reuse in related areas.
  • e.g. IStream is widely used for reading or
    writing streams of bytes
  • "Local/Remote Transparency."
  • Interface can hide networking issues from
    programmer
  • Programming language independence.

14
GUIDs
  • Globally Unique Identifiers (GUIDs)
  • 128-bit integers unique across space and time
  • Used to identify every interface and every
    component object class
  • UUIDs defined by OSF's Distributed Computing
    Environment.
  • Used at bind time to avoid false connections
    between components.
  • CLSIDs
  • GUIDs for component object classes
  • IIDs
  • GUIDs for interfaces.

15
IUnknown
  • An interface providing vital functions
  • All COM objects must provide IUnknown
  • Interfaces must inherit from IUnknown
  • interface IUnknown
  • virtual HRESULT QueryInterface(IID iid,
    void ppObj)0
  • virtual ULONG AddRef() 0
  • virtual ULONG Release() 0

16
IUnknown Methods
  • AddRef and Release
  • Simple reference counting methods.
  • Control interface and object lifetime
  • QueryInterface allows clients
  • To find at run time if an interface is supported
    by a component
  • To get an interface from a COM object.

17
Cross-Process Interaction
  • Different Address Spaces
  • Each process has its own address space
  • (more or less!)
  • Cannot share pointer (or related data)
  • Copying pointers from one space to another fails.
  • (Just as you can't write pointers to a file)

18
Concurrency
  • Applications run code independently
  • Need care in exchanging data to avoid races
    mutual exclusion errors.

19
Component Creation
  • Application passes the CLSID of COM class
  • COM library finds server code in the registry
  • COM loads the server code
  • (if it's not already available)
  • If the server is an executable,
  • COM launches the .EXE file
  • waits for it to register a class factory to
    create components
  • If the server is a dynamic-link library (DLL),
  • COM loads the DLL and calls DllGetClassFactory
  • COM asks the object's IClassFactory to create a
    component object gets the interface
  • COM returns requested interface pointer to the
    calling application.

20
Component Problem Solved?
  • Basic Interoperability
  • vtables define a binary interface standard
  • Type representations defined
  • Note at higher level (OLE)
  • library support for interaction protocols
  • (e.g. dragdrop)

21
Versioning
  • Add new functionality by adding support for new
    interfaces.
  • Old components can rely on the immutable old
    interfaces
  • QueryInterface determines the current
    capabilities efficiently
  • Applications that know how to use new facilities
    can do so
  • Information hiding allows performance improvement

22
COM and versioning
23
Language Location Independence
  • Components can be implemented used in different
    languages.
  • Transparent Cross-Process Interoperability
  • Hide inter-process and cross-network details
    behind interface calls

24
High Performance
  • Calls to a 'same process' component are as fast
    as a C method call

25
Summary
  • COM
  • Location Independence
  • Proxy/stub
  • Vendor/Language Independence
  • Binary standard
  • Versioning
  • Interface
  • IUnknown
  • GUID
  • Immutable

26
Component Object Library
  • Run-time system supporting COM.
  • Facilities
  • To make IUnknown calls across processes
  • To launch components
  • To set up connections between components
  • To manage across interaction networks
  • DCOM
Write a Comment
User Comments (0)
About PowerShow.com