Solved

Interface pointers?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C language IDE ā€“ Compilers installation 14 75
C++ standard library based binary archive format 6 104
max float value 3 51
No module found pypyodbc, 3 32
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

860 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