Solved

Interface pointers?

Posted on 2000-02-15
3
224 Views
Last Modified: 2010-04-10
What I'm trying to accomplish:
1.  I have a listener app that waits for a request from a client.
2.  Client connects and request data whenever that listener app gets it.

Generally, I have written programs where the client app pull information from an COM/DCOM object.  I have not written anything where the client makes the initial connection and its up to the DCOM object to push info to the client as it receives it.  
Someone told me that the client would have to pass an interface pointer to the DCOM object so it would know how to get to the client.  Is this true?  If so, how do I proceed.  If there is a better way, let me know.  
0
Comment
Question by:ivanh
3 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 2525086
Of course you have to pass something to the object so it know how to communicate with your client.  The normal way for a COM object to communicate back to a client is via a connection point.
0
 

Accepted Solution

by:
mstout earned 200 total points
ID: 2525199
I think your source is correct.

1) the client needs to connect to the server.  It does this by CoCreateInstanceEx using the hostname of the server machine.

2 simple) Server creates a new object

2 advanced) Server creates a new object if one doesnt exist, or if one exists, just return the current object.
(see DECLARE_CLASSFACTORY_SINGLETON in atl doc).

3) Create a callback interface (say IMyProjCallback) that the server calls when data has changed.

4) Create a method on the server object to register the callback and returning a cookie so that
the client can unadvise.  call it Advise(IMyProjCallback *,DWORD *Cookie)

5) Implement this method by a) create a cookie, store the cookie and the interface pointer in some data structure. (AddRefing where appropriate)

6) Create a method on the server object to unregister the callback. Call it Unadvise(DWOORD cookie)

7) Implement this method by looking up the cookie in the data structure and releasing the interface.

8) When the data changes in your server, Just go through your data structure and call the all the IMyProjCallback interfaces


9) Gee ... this sounds a lot like the IConnectionPoint interfaces: IConnectionPoint,IConnectionPointContainer. You could probably
leverage IConnectionPointImpl template in atl.

10) Problems to deal with a) circular refrences: Server holds on to client and client holds on to server. b) Client and/or server dying...
need to clean up your COOKIE,Interface map when client callback fails.
0
 
LVL 1

Author Comment

by:ivanh
ID: 2528865
jhance:  I realize that and that's assumed, but the real question was implementing a push model vs. a pull.

mstout:  Thanks, I passed it back to my source and he agreed 100% on your comments.  Thankyou.  This gives me a good outline.  This concept is new to me and he helped by explaining your comments.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now