Re: Igor, pAPP toolkit questions

From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 12/17/04


Date: Fri, 17 Dec 2004 11:07:16 -0500


"Josh Mclaren" <optics201@optonline.com> wrote in message
news:1103298672.497545.42660@z14g2000cwz.googlegroups.com
> Since the Read method we have implemented needs to stay within
> CTestAPP, what would help us is the ability to have CTestAPP and
> CTestSink share information. I did some experimentation with
> implementing methods such as Start in CTestAPP, but I'm still not sure
> how to get a handle to CTestSink.

Are you using the older or newer version of my code? You can easily see
the difference in how CustomSinkStartPolicy is used:

// old
CustomSinkStartPolicy<CTestSink>
// new
CustomSinkStartPolicy<CTestAPP, CTestSink>

In the old version, the sink is actually a data member of the APP, named
m_internetSink. So the APP can access the sink directly. To provide
access the other way, add an Init(CTestAPP*) method to the sink and call
it in the APP's constructor, for example.

In the new version, CustomSinkStartPolicy has three methods, like this

template <class Protocol, class Sink>
class CustomSinkStartPolicy
{
public:
 static Sink* GetSink(const Protocol* pProtocol);
 Sink* GetSink() const;
 static Protocol* GetProtocol(const Sink* pSink);
};

So, you can write something like this:

class CTestAPP;
class CTestSink;
typedef CustomSinkStartPolicy<CTestAPP, CTestSink> StartPolicy;

class CTestAPP : public StartPolicy {...}

Then from inside CTestAPP's methods you can call GetSink() to get
CTestSink* pointer. Or, you can call StartPolicy::GetSink(this). From
inside the sink, call StartPolicy::GetProtocol(this) to get CTestAPP*
pointer.

-- 
With best wishes,
    Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925 


Relevant Pages