Solved

Interface pointers?

Posted on 2000-02-15
3
227 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 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