What is COM/DCOM. Distributed Object Systems 4 COM/DCOM. COM vs Corba 1. COM vs. Corba 2. Multiple inheritance vs multiple interfaces



Similar documents
COM+ OVERVIEW OF MICROSOFTS COM, DCOM AND COM+ COMPONENT TECHNOLOGIES DCOM - COM+ Peter R. Egli INDIGOO.COM. indigoo.com. 1/20 Rev. 1.

Lehrstuhl für Informatik 4 Kommunikation und verteilte Systeme. Middleware. Chapter 8: Middleware

How To Use A Com In A Microsoft Com 2.5 (Dsi) (Dsi) (For Microsoft) (Com) (Sib) (Operations) (Orchestra) (Ahem) (I

Infrastructure that supports (distributed) componentbased application development

The Microsoft Way: COM, OLE/ActiveX, COM+ and.net CLR. Chapter 15

DCOM and CORBA Side by Side, Step by Step, and Layer by Layer

Middleware Lou Somers

MS ACCESS DATABASE DATA TYPES

Java and ActiveX Projects

Corba. Corba services. The (very) global picture. Corba. Distributed Object Systems 3 CORBA/IDL. Corba. Features. Services


Module 17. Client-Server Software Development. Version 2 CSE IIT, Kharagpur

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

Distributed Network Management Using SNMP, Java, WWW and CORBA

The programming language C. sws1 1

Interface Definition Language

Agilent PNA Microwave Network Analyzers

CS 378 Big Data Programming. Lecture 9 Complex Writable Types

Introduction CORBA Distributed COM. Sections 9.1 & 9.2. Corba & DCOM. John P. Daigle. Department of Computer Science Georgia State University

Crash Course in Java

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

3F6 - Software Engineering and Design. Handout 10 Distributed Systems I With Markup. Steve Young

C++FA 5.1 PRACTICE MID-TERM EXAM

Introduction to SQL for Data Scientists

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

Middleware and Distributed Systems. Introduction. Dr. Martin v. Löwis

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Introduction to Distributed Computing using CORBA

Pemrograman Dasar. Basic Elements Of Java

Implementation Aspects of OO-Languages

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

El Dorado Union High School District Educational Services

An Overview of Java. overview-1

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents

L7_L10. MongoDB. Big Data and Analytics by Seema Acharya and Subhashini Chellappan Copyright 2015, WILEY INDIA PVT. LTD.

[MS-RDPESC]: Remote Desktop Protocol: Smart Card Virtual Channel Extension

Java (12 Weeks) Introduction to Java Programming Language

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

CORBA Programming with TAOX11. The C++11 CORBA Implementation

Habanero Extreme Scale Software Research Project

Outline SOA. Properties of SOA. Service 2/19/2016. Definitions. Comparison of component technologies. Definitions Component technologies

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

CAPIX Job Scheduler User Guide

Object Oriented Software Design II

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Introduction to Java

Interface Definition Language

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Semantic Analysis: Types and Type Checking

The C Programming Language course syllabus associate level

Web Services. Distributed Object Systems 11. Web Services, SOAP and NET. Web Applications. Web Services. Web services vs Distributed Objects

Java programming for C/C++ developers

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

MS Access Lab 2. Topic: Tables

[MS-EVEN]: EventLog Remoting Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

Introduction to Data Structures

Introduction. Why (GIS) Programming? Streamline routine/repetitive procedures Implement new algorithms Customize user applications

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

4D Plugin SDK v11. Another minor change, real values on 10 bytes is no longer supported.

Comparative Study of C, C++, C# and Java Programming Languages

Programming Languages CIS 443

Visual Basic Programming. An Introduction

Java Interview Questions and Answers

Programming languages C

Towards practical reactive security audit using extended static checkers 1

COM Connect User's Guide. VisualWorks 7.8 P SIMPLIFICA TION THROUGH I NNOV A TION

ECS 165B: Database System Implementa6on Lecture 2

An Incomplete C++ Primer. University of Wyoming MA 5310

Facebook Twitter YouTube Google Plus Website

Lecture 7: Programming for the Arduino

Government Girls Polytechnic, Bilaspur

Lecture 7: Java RMI. CS178: Programming Parallel and Distributed Systems. February 14, 2001 Steven P. Reiss

SQL and Programming Languages. SQL in Programming Languages. Applications. Approaches

Keysight Technologies PNA Microwave Network Analyzers

Chapter 2: Remote Procedure Call (RPC)

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

[MC-IISA]: Internet Information Services (IIS) Application Host COM Protocol

Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

User Manual. 3-Heights PDF Producer API. Version 4.6

Field Properties Quick Reference

Getting Started with the Internet Communications Engine

APPLICATION PROGRAMMING INTERFACE

MPLAB Harmony System Service Libraries Help

1 The Java Virtual Machine

ODBC Client Driver Help Kepware, Inc.

Lecture 22: C Programming 4 Embedded Systems

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

[MS-FAX]: Fax Server and Client Remote Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Binary storage of graphs and related data

C# and Other Languages

Transcription:

Distributed Object Systems 4 COM/DCOM Piet van Oostrum Sept 18, 2008 What is COM/DCOM Component Object Model Components (distributed objects) à la Microsoft Mainly on Windows platforms Is used in large parts of Windows itself COM is local version, DCOM is distributed version Microsoft wants it to be replaced by.net Originally developed to connect MS Word and Excel OLE: Object Linking and Embedding Later: generalisation: basic object communication mechanism could be used for other things: COM Mozilla s XPCOM and UNO (OpenOffice.org) are similar Piet van Oostrum 1 COM vs Corba 1 Corba is platform independent COM is Microsoft-only Corba is multi-vendor COM comes with Windows. Corba must be installed separately Corba specifies how remote objects must be called (source code) COM defines a binary standard (implementation) Corba and COM have a similar structure (Services, etc.) COM vs. Corba 2 Interfaces COM objects can have more than one interface Corba objects have a single interface (Corba Component Model supports multiple interfaces) Identity Corba objects are identified by an object reference COM objects have one or more interface pointers Inheritance COM and Corba have interface inheritance COM has single inheritance Corba has multiple inheritance Piet van Oostrum 2 Piet van Oostrum 3 Multiple inheritance vs multiple interfaces Suppose you have an interface for printing and an interface for storage: Print interface: set_page(pagesize) build_pages(page_numbers) printit() Storage interface: open_container(filename) read_object(obj_id) write_object(obj_id) Defining an object that supports both interfaces: In COM: the object implements both interfaces In Corba: inherit from both: interface MyClass: Print, Storage COM What s in it? COM is a mechanism to call objects (local or remote), compare Corba s ORB Many services are defined that use COM (big parts of Windows O.S.) OLE Documents: Linking Embedding In-place activation (OLE) Automation (how to command an application from another application) Events... Piet van Oostrum 4 Piet van Oostrum 5 slides4.pdf September 18, 2008 1

Interfaces The interfaces to an object must be implemented in a specific binary way. This is derived from the way Visual C++ implements objects and methods. For COM objects this implementation must be used in all programming languages The interface can be described with (Microsoft) IDL Visual C++ object var1 var2 method table method code Object have a pointer to a (an array of method pointers) This is followed by the instance variables Often a pointer to the object is passed around (object*) Piet van Oostrum 6 Piet van Oostrum 7 COM Interface COM Interface - Subclasses method code class A { (){; (){; (){; (){; class B extends A { m5(){; m6(){; method table A COM interface is implemented as a pointer to a pointer to a list of function addresses (interface pointer) A COM object must implement at least one interface A COM object may implement more than one interface COM objects written in VC++ can use a pointer to themselves (this) as interface pointer A The for a subinterface is just an extension (more methods at the end) of the superinterface so the subinterface pointer can be used where the superinterface is needed B m5 m6 Piet van Oostrum 8 Piet van Oostrum 9 Interface pointer Notation client uses interface pointer: Interface A Object Interface B Client Object In the case of a remote object, the pointer refers to a proxy object. IUnknown Every interface must have the following methods in the first 3 slots: QueryInterface (IID) For finding other interfaces AddRef () For counting how many references there are Release () For releasing a reference These three methods together form the interface IUnknown (Most people use names starting with I for interfaces) There is no concept of object pointer Piet van Oostrum 10 Piet van Oostrum 11 slides4.pdf September 18, 2008 2

Identification A method from an interface is not identified by name, but by its position in the method table 0=QueryInterface 1=AddRef 2=Release, etc. An (abstract) interface is identified by a 128-bit (usually random-like) number: GUID (Globally Unique Identifier) or UUID (Universally Unique Identifier) UUID is a DCE term. There are utilities to generate GUID s IUnknown QueryInterface on an object with a UUID for an interface as parameter returns an interface pointer for that interface (and the same object) if it exists. QueryInterface could return any interface pointer that has the proper slots (e.g. a subinterface) AddRef and Release together form a simple garbage collection mechanism (refcount): When the refcount for all interfaces of an object together reaches 0, the object can delete itself These three methods can be used with any interface Piet van Oostrum 12 Piet van Oostrum 13 Object identity There are no object pointers Any interface pointer for an object can be used to identify the object Two different interface pointers could identify the same object Object identity: A QueryInterface call for IUnknown for the same object should always give the same interface pointer regardless of the interface upon which it is called. MIDL Microsofts IDL is derived from OSF DCE s IDL. MIDL is similar to Corba IDL but uses a different syntax It also specifies the UUID s Interfaces can be grouped in classes and classes in libraries An interface can be used in many classes Classes are used to create objects Classes and libraries are also identified by GUID s Class GUID s (CLSID) are stored in the Windows registry with information how to run the code that implements the objects Piet van Oostrum 14 Piet van Oostrum 15 Example IDL [object, uuid(3cfdb283-ccc5-11d0-ba0b-00a0c90df8bc) ] interface IStat: IUnknown { import "unknwn.idl"; init(); additem([in] double item); getavg([out] double *avg); getnum([out] long *num); getall([out] double *avg, [out] long *num); ; Conventionally a return code signifies if the operation succeeded or not (there are no exceptions). Method results are returned through out parameters. MIDL types boolean 8 bits byte 8 bits. char 8 bits. double 64-bit floating point number. float 32-bit floating point number. hyper 64-bit integer. int 32-bit integer. long 32-bit integer. short 16-bit integer. small 8-bit integer. wchar_t 16-bit wide characters. struct, union, array (fixed or dynamic), enum Piet van Oostrum 16 Piet van Oostrum 17 slides4.pdf September 18, 2008 3

Examples of structs and arrays Use of dynamic arrays #define MAX_INDEX 10 typedef char ATYPE[MAX_INDEX]; typedef short BTYPE[]; // Equivalent to [*]; typedef long CTYPE[*][10]; // [][10] typedef float DTYPE[0..10]; // Equivalent to [11] typedef float ETYPE[0..(MAX_INDEX)]; typedef struct { unsigned short size; unsigned short length; [size_is(size), length_is(length)] char string[*]; counted_string; MyFunction( [in, out] short * psize, [in, out, string, size_is(*psize)] char a[0..*] ); psize is the size of the array, given as separate parameter. IDL tells that this parameter really is the size of the array (needed for marshalling the proper number of elements) size_is is the number of elements reserved, length_is is the actual number of elements present if different Piet van Oostrum 18 Piet van Oostrum 19 Unions Encapsulated union (with a discriminator) typedef union S1_TYPE switch (long l1) U1_TYPE { case 1024: float f1; case 2048: double d2; ; S1_TYPE will be a struct in C/C++ with members the long l1 and the union with name U1_TYPE. There are also other notations. Where are objects running? In a DLL: The DLL is loaded if necessary (first occurrence) and the client gets the real pointer to the object interface (in C++ could be the object pointer). Runs in the same process as the client This is called inproc server Method call is as fast as normal In another process on the same machine The process is started if necessary In the client process a proxy object is created with the same interface The proxy object uses RPC mechanisms to the real object This is called local server Piet van Oostrum 20 Piet van Oostrum 21 Where are objects running? In another machine Is used similar to local server RPC is over the network In the registry there is information about inproc or local server Also contains the location of the DLL and/or.exe file The client can specify inproc or local server For DCOM if the object is not found on the local machine, COM asks other machines if the object is there Remote objects must be separately registered in the registry How to create (or get) objects Use the class object The COM runtime system (Service Control Manager) can find the class object, given a CLSID, from the registry It will also start a server or load a DLL if necessary The Class object should be a singleton (only one instance) It should provide methods to create objects or find existing ones. The function CoGetClassObject gets the class object, given a CLSID, interface ID and inproc/local/remote It returns an interface pointer for the class object Piet van Oostrum 22 Piet van Oostrum 23 slides4.pdf September 18, 2008 4

Integrated method Use CoCreateInstance This creates a class object and calls its CreateInstance method to get an object (instance) Must implement interface IFactory There is also an interface IFactory2 which supports licensing CoCreateInstance parameters: class id an Outer pointer (see later) inproc/local/remote interface id (GUID) for the object Client code double value; CoInitialize(NULL); // initialize COM CoCreateInstance(CLSID_CStat, NULL, CLSCTX_SERVER, IID_IStat, (void**) &pistat); pistat->additem(value); pistat->queryinterface(iid_istat2, (void**) &pistat2); pistat->release(); pistat2->count(value); pistat2->release(); CoUninitialize(); Piet van Oostrum 24 Piet van Oostrum 25 Client side Client COM library COM runtime system (6) (1) (2) [3] [1] [2] [4] [5] (4) Server 1: CocreateInstance, 2: server started, 3: class object created, 4: IFactory interface called, 5: object created, 6: object interface pointer returned, [1],[2],[3]: calls to pistat, [4],[5]: calls to pistat2 class factory (3) (5) object COM library Implementation Every object must implement the IUnknown methods: #define STDMETHODIMP stdcall STDMETHODIMP Stat::QueryInterface(REFIID riid, void** ppv) { if (riid == IID_IUnknown riid == IID_IStat) *ppv = (IStat*) this; // if more interfaces are supported // else if (riid ==... else { *ppv = NULL; return E_NOINTERFACE; AddRef(); return S_OK; In Visual C++ there are different function calling mechanisms. For COM objects stdcall must be used. Piet van Oostrum 26 Piet van Oostrum 27 RefCount Class Factory int refcnt; STDMETHODIMP Stat::AddRef() { refcnt++; STDMETHODIMP Stat::Release() { refcnt--; if (refcnt == 0) {... STDMETHODIMP CClassFactory::CreateInstance(LPUNKNOWN p, REFIID riid, void** ppv) { IStat* punk = (IStat*) new Stat(); hr = punk->queryinterface(riid, ppv); return hr; The CreateInstance method creates a new Stat object and returns its interface pointer for the interface iid. QueyInterface will do the required AddRef. Piet van Oostrum 28 Piet van Oostrum 29 slides4.pdf September 18, 2008 5

Our own Methods Server code STDMETHODIMP Stat::addItem (double d) { sum += d; n++; return S_OK; STDMETHODIMP Stat::getAvg (double* d) { *d = sum/n; // should check n!=0 return S_OK; void main() {... hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); CClassFactory* fact = new CClassFactory; hr = CoRegisterClassObject(CLSID_CStat, fact, CLSCTX_SERVER, REGCLS_MULTIPLEUSE, &dwregister);... register the class object Piet van Oostrum 30 Piet van Oostrum 31 Finally COM is optimized for local calls (especially inproc). Is a very popular mechanism on the MS Windows operating system DCOM (distributed version) has never become popular Is now gradually superseded by.net Mainly used in C, C++ and Visual Basic It has a lot of complicated issues Java support is minimal No multi-platform support Piet van Oostrum 32 slides4.pdf September 18, 2008 6