?
Solved

Interface pointers?

Posted on 2000-02-15
3
Medium Priority
?
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

650 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