Midterm Exam 2 with Answer Key - Distributed Objects | CSE 775, Exams of Engineering

Material Type: Exam; Professor: Fawcett; Class: Distributed Objects; Subject: Computer Engineering; University: Syracuse University; Term: Spring 2008;

Typology: Exams

Pre 2010

Uploaded on 08/09/2009

koofers-user-0fr-1
koofers-user-0fr-1 🇺🇸

10 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE775 – Distributed Objects Spring 2008
Midterm #2 Examination
Name:_______Instructor’s Solution________________ SUID:____________________
This is a closed book examination. Please place all your books on the floor
beside you. You may keep one page of notes on your desktop in addition to
this exam package. All examinations will be collected promptly at the end of
class. Please be prepared to quickly hand in your examination at that time.
If you have any questions, please do not leave your seat. Raise your hand
and I will come to your desk to discuss your question. I will answer all
questions about the meaning of the wording of any question. I may choose
not to answer other questions.
You will find it helpful to review all questions before beginning. All questions
are given equal weight for grading, but not all questions have the same
difficulty. Therefore, it is very much to your advantage to answer first those
questions you believe to be easiest.
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Midterm Exam 2 with Answer Key - Distributed Objects | CSE 775 and more Exams Engineering in PDF only on Docsity!

Midterm #2 Examination

Name:_______Instructor’s Solution________________ SUID:____________________

This is a closed book examination. Please place all your books on the floor

beside you. You may keep one page of notes on your desktop in addition to

this exam package. All examinations will be collected promptly at the end of

class. Please be prepared to quickly hand in your examination at that time.

If you have any questions, please do not leave your seat. Raise your hand

and I will come to your desk to discuss your question. I will answer all

questions about the meaning of the wording of any question. I may choose

not to answer other questions.

You will find it helpful to review all questions before beginning. All questions

are given equal weight for grading, but not all questions have the same

difficulty. Therefore, it is very much to your advantage to answer first those

questions you believe to be easiest.

1. What is a component? Why are components important and useful

software constructs? Describe their essential parts and discuss why each

part is necessary.

Answer:

A component is an encapsulated set of functionality that is accessed

through an interface and uses an object factory to create instances of the

class(es) that implement the interface.

The interface serves as a contract between component and its clients for

services. The Object factory is called by clients of the component to

create instances of the class that implements its interface and binds it to

the client through an interface pointer. Since the client holds only a

pointer to the interface type and calls only through that and the object

factory, its source text has no dependencies on the concrete types used

for the component implementation.

This means that the component can be changed without rebuilding the

client. We simply modify the component as needed, build it, and place

the newly build dynamic link library where the client will load it.

COM components provide the additional feature of language and

threading model independence. A client, built in any language that can

make COM calls, can interoperate with the component, regardless of its

source language, provided that it exposes a COM dual interface (at least

an IDispatch interface) as well as the IClassFactory interface.

COM components also provide for type queries using QueryInterface and

provide type libraries that can be used to support late binding between

client and component.

3. For your design of Project #2, describe all the actions taken by the COM

run-time when the client instantiates the Host. Please consider all parts

of the system.

Answer:

The Host is an out-of-proc COM component, so:

COM, in response to a client’s call to CoCreateInstance, searches the

registry for the component’s CLSID and calls CreateProcess. It then waits

for the server to create an instance of its class factory and register it in a

process-wide table. COM retrieves the pointer to the class factory from

the table, calls its CreateInstance function, and returns a pointer to the

requested interface.

The Host loads the FileHandler and DataSender in-process components,

so:

COM, in response to the Host’s calls to CoCreateInstance, searches the

registry for component’s CLSID, loads library, and calls GetProcAddress for

DllGetClassObject. It uses that to get a pointer to the component’s class

factory, calls its CreateInstance method, and returns a pointer to the Host

for the requested interface.

4. Describe the responsibilities for managing memory allocations for an [in,

out] parameter in a COM interface. Write code for both client and COM

component to pass a BSTR holding a string with more than zero

characters, append additional characters in the component, return the

modified BSTR to the client, and display the results.

Answer:

For [in, out] parameters, the client is responsible for allocating and

deallocating memory for the passed parameter, using the appropriate

COM allocator.

// StringAppenderClient.cpp - Demonstrate Solution to MT2-Q4 // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 08 // /////////////////////////////////////////////////////////////// #include <atlbase.h> #include #include "../StringAppender/StringAppender_i.h" int main( int argc, char* argv[]) { CoInitialize(NULL); CComQIPtr pStringAppender; pStringAppender.CoCreateInstance(CLSID_AppendString); if(pStringAppender) { BSTR send = SysAllocString(L "client string"); HRESULT hr = pStringAppender->AppendString(&send); if(SUCCEEDED(hr)) { std::wcout << "\n " << send; SysFreeString(send); } } std::wcout << "\n\n"; return 0; } /////////////////////////////////////////////////////////// // AppendString.cpp - Demonstrate Solution to MT2-Q4 // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 08 // /////////////////////////////////////////////////////////// #include "stdafx.h" #include "AppendString.h" STDMETHODIMP CAppendString::AppendString(BSTR* Str) { CComBSTR appender(Str); appender += L* " plus this appended string"; SysFreeString(Str); Str = appender.Detach(); return S_OK; }

6. What is a memory mapped file and how does it relate to the Windows

virtual memory management system.

Answer:

Memory mapped files are memory page(s), as defined by the Windows

virtual memory system, that have an associated file mapping kernel

object created when you call CreateFileMapping. To access the mapped

file, e.g., the memory page, you call MapViewofFile(Ex).

When accessed, this page is loaded into memory and the accessor gets a

pointer, relative to it’s virtual address space, to the beginning of the

memory allocated.

Two processes can access the same shared memory by each calling

CreateFileMapping with the same name. The first caller creates the kernel

object and its associated page(s), receiving a handle to the kernel object.

Subsequent callers, if they use the same name, get handles that refer to

the same kernel object and associated page(s). When they call

MapViewofFile(Ex) they also get pointers, relative to their own virtual

address space, that point to the beginning of the shared page.

7. Why is IDL used in COM to specify an interface contract instead of a

header file defining an abstract class?

Answer:

IDL is used to provide a language-independent way of describing a

component’s interfaces and type libraries. This allows a client built in one

language to access and use the facilities of a component built with

another programming language. It also provides attributes, e.g., [in, out,

retval, and size_is(…)] that support marshaling of data between COM

apartments.

The types used to describe interfaces with IDL are not language specific

types. Instead, COM uses the Network Data Representation (NDR) types,

which all have specified sizes, necessary for data marshaling.

For COM components, the MIDL compiler processes IDL to create a header

file that contains interface declarations, tied to specific GUIDS, and is

used by the C++ compiler to layout an interface’s virtual function pointer

table (vtbl). This file also defines C structures that act like vtbls that can

be processed by C compilers. MIDL also produces a type library that

languages like Visual Basic (pre .Net) use to bind at run-time to the

component, using its IDispatch interface.