1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/ipcclient.cpp
3 // Purpose: wxIPC client side benchmarks
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/evtloop.h"
16 #include "../../samples/ipc/ipcsetup.h"
21 class PokeAdviseConn
: public wxConnection
24 PokeAdviseConn() { m_gotAdvised
= false; }
36 const wxString
& GetItem() const { return m_item
; }
38 virtual bool OnAdvise(const wxString
& topic
,
46 if ( topic
!= IPC_BENCHMARK_TOPIC
||
47 item
!= IPC_BENCHMARK_ITEM
||
48 !IsTextFormat(format
) )
54 m_item
= GetTextFromData(data
, size
, format
);
63 DECLARE_NO_COPY_CLASS(PokeAdviseConn
)
66 class PokeAdviseClient
: public wxClient
69 // provide a convenient helper taking care of connecting to the right
70 // server/service/topic and returning the connection of the derived type
71 // (or NULL if we failed to connect)
72 PokeAdviseConn
*Connect()
74 wxString host
= Bench::GetStringParameter();
79 int port
= Bench::GetNumericParameter();
81 service
= IPC_SERVICE
;
83 service
.Printf("%d", port
);
85 return static_cast<PokeAdviseConn
*>(
86 MakeConnection(host
, service
, IPC_BENCHMARK_TOPIC
));
90 // override base class virtual to use a custom connection class
91 virtual wxConnectionBase
*OnMakeConnection()
93 return new PokeAdviseConn
;
97 class PokeAdvisePersistentConnection
100 PokeAdvisePersistentConnection()
102 m_client
= new PokeAdviseClient
;
103 m_conn
= m_client
->Connect();
105 m_conn
->StartAdvise(IPC_BENCHMARK_ITEM
);
108 ~PokeAdvisePersistentConnection()
112 m_conn
->StopAdvise(IPC_BENCHMARK_ITEM
);
113 m_conn
->Disconnect();
119 PokeAdviseConn
*Get() const { return m_conn
; }
122 PokeAdviseClient
*m_client
;
123 PokeAdviseConn
*m_conn
;
126 DECLARE_NO_COPY_CLASS(PokeAdvisePersistentConnection
)
129 PokeAdvisePersistentConnection
*theConnection
= NULL
;
133 theConnection
= new PokeAdvisePersistentConnection
;
134 if ( !theConnection
->Get() )
136 delete theConnection
;
137 theConnection
= NULL
;
146 delete theConnection
;
149 } // anonymous namespace
151 BENCHMARK_FUNC_WITH_INIT(IPCPokeAdvise
, ConnInit
, ConnDone
)
155 PokeAdviseConn
* const conn
= theConnection
->Get();
157 const wxString
s(1024, '@');
159 if ( !conn
->Poke(IPC_BENCHMARK_ITEM
, s
) )
162 while ( !conn
->GotAdvised() )
165 if ( conn
->GetItem() != s
)