🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #3134

Re: sockets????

#3134
From: Remy Lebeau (TeamB)
Date: Wed, 02 Nov 2005 09:04
140 lines
5249 bytes
"Gary D" <gcdesroches@nctc.com> wrote in message
news:4367f582@newsgroups.borland.com...

> Here is the TestEventsImplImpl.cpp File as modified to add your code:

You are going about it all wrong.  Your Trigger() code should not be using
the TThreadList at all, unless you want clients to broadcast events to other
clients.  The rest of the server code should be using the TThreadList to
reach the Fire_...() methods for each individual client.

Try this code instead:

    class ATL_NO_VTABLE TTestEventsImplImpl :
        public CComObjectRootEx<CComSingleThreadModel>,
        public CComCoClass<TTestEventsImplImpl, &CLSID_TestEventsImpl>,
        public IConnectionPointContainerImpl<TTestEventsImplImpl>,
        public TEvents_TestEventsImpl<TTestEventsImplImpl>,
        public IDispatchImpl<ITestEventsImpl, &IID_ITestEventsImpl,
&LIBID_TestEventsTypeLib>
    {
    public:
        static TThreadList* InterfaceList;

        TTestEventsImplImpl();
        ~TTestEventsImplImpl();

        // Data used when registering Object
        //
        DECLARE_THREADING_MODEL(otApartment);
        DECLARE_PROGID("TestEventsTypeLib.TestEventsImpl");
        DECLARE_DESCRIPTION("");

        // Function invoked to (un)register object
        //
        static HRESULT WINAPI UpdateRegistry(BOOL bRegister)
        {
            TTypedComServerRegistrarT<TTestEventsImplImpl>
                regObj(GetObjectCLSID(), GetProgID(), GetDescription());
            return regObj.UpdateRegistry(bRegister);
        }

        BEGIN_COM_MAP(TTestEventsImplImpl)
            COM_INTERFACE_ENTRY(ITestEventsImpl)
            COM_INTERFACE_ENTRY2(IDispatch, ITestEventsImpl)
            COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
        END_COM_MAP()

        BEGIN_CONNECTION_POINT_MAP(TTestEventsImplImpl)
            CONNECTION_POINT_ENTRY(DIID_ITestEventsImplEvents)
        END_CONNECTION_POINT_MAP()

    public:
        static void TriggerOnAllClients();

    // ITestEventsImpl
    public:
        STDMETHOD(Trigger());
    };


    TThreadList* TTestEventsImplImpl::InterfaceList = NULL;

    TTestEventsImplImpl::TTestEventsImplImpl()
    {
        if( !InterfaceList )
            InterfaceList = new TThreadList;
        if( InterfaceList )
            InterfaceList->Add(this);
    }

    TTestEventsImplImpl::~TTestEventsImplImpl()
    {
        if( InterfaceList )
        {
            int count;

            TList *list = InterfaceList->LockList();
            try
            {
                list->Remove(this);
                count = list->Count;
            }
            __finally {
                InterfaceList->UnlockList();
            }

            if( count < 1 )
            {
                delete InterfaceList;
                InterfaceList = NULL;
            }
        }
    }

    void TTestEventsImplImpl::TriggerOnAllClients()
    {
        if( InterfaceList )
        {
            TList *list = InterfaceList->LockList();
            try
            {
                for(int x = 0; x < list->Count; ++x)
                {
                    try
                    {
                        TTestEventsImplImpl *pIntf = (TTestEventsImplImpl *)
list->Items[x];
                        if( pIntf )
                            pIntf->Trigger();
                    }
                    catch(...) { }
                }
            }
            __finally {
                InterfaceList->UnlockList();
            }
        }
    }

    STDMETHODIMP TTestEventsImplImpl::Trigger()
    {
        WideString strName(L"Whatever");
        Fire_Event1(strName);
        return S_OK;
    }


You can then do the following where desired in the server code:

    void TCOMServerCode::DoSomething()
    {
        // ...
        if( something happened )
            TTestEventsImplImpl::TriggerOnAllClients();
        // ...
    }


Gambit
Technical Details
Message-ID: <43688124$3@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43599303@newsgroups.borland.com> <43599f5f$1@newsgroups.borland.com> <435bbbf2$1@newsgroups.borland.com> <435bc353$1@newsgroups.borland.com> <435ea916$1@newsgroups.borland.com> <435eb30b@newsgroups.borland.com> <436367ef$1@newsgroups.borland.com> <4363be5e$1@newsgroups.borland.com> <4366d403@newsgroups.borland.com> <43670f39$2@newsgroups.borland.com> <4367f582@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,b9d755a2fd611a30
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <43599303@newsgroups.borland.com> <43599f5f$1@newsgroups.borland.com> <435bbbf2$1@newsgroups.borland.com> <435bc353$1@newsgroups.borland.com> <435ea916$1@newsgroups.borland.com> <435eb30b@newsgroups.borland.com> <436367ef$1@newsgroups.borland.com> <4363be5e$1@newsgroups.borland.com> <4366d403@newsgroups.borland.com> <43670f39$2@newsgroups.borland.com> <4367f582@newsgroups.borland.com>
Subject: Re: sockets????
Date: Wed, 2 Nov 2005 01:04:40 -0800
Lines: 142
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <43688124$3@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1130922276 68.69.17.41 (2 Nov 2005 01:04:36 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail