1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/ipcclient.cpp
3 // Purpose: wxIPC client side benchmarks
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/evtloop.h"
14 // do this before including wx/ipc.h under Windows to use TCP even there
15 #define wxUSE_DDE_FOR_IPC 0
17 #include "../../samples/ipc/ipcsetup.h"
22 class PokeAdviseConn
: public wxConnection
25 PokeAdviseConn() { m_gotAdvised
= false; }
37 const wxString
& GetItem() const { return m_item
; }
39 virtual bool OnAdvise(const wxString
& topic
,
47 if ( topic
!= IPC_BENCHMARK_TOPIC
||
48 item
!= IPC_BENCHMARK_ITEM
||
49 !IsTextFormat(format
) )
55 m_item
= GetTextFromData(data
, size
, format
);
64 DECLARE_NO_COPY_CLASS(PokeAdviseConn
)
67 class PokeAdviseClient
: public wxClient
70 // provide a convenient helper taking care of connecting to the right
71 // server/service/topic and returning the connection of the derived type
72 // (or NULL if we failed to connect)
73 PokeAdviseConn
*Connect()
75 wxString host
= Bench::GetStringParameter();
80 int port
= Bench::GetNumericParameter();
82 service
= IPC_SERVICE
;
84 service
.Printf("%d", port
);
86 return static_cast<PokeAdviseConn
*>(
87 MakeConnection(host
, service
, IPC_BENCHMARK_TOPIC
));
91 // override base class virtual to use a custom connection class
92 virtual wxConnectionBase
*OnMakeConnection()
94 return new PokeAdviseConn
;
98 class PokeAdvisePersistentConnection
101 PokeAdvisePersistentConnection()
103 m_client
= new PokeAdviseClient
;
104 m_conn
= m_client
->Connect();
106 m_conn
->StartAdvise(IPC_BENCHMARK_ITEM
);
109 ~PokeAdvisePersistentConnection()
113 m_conn
->StopAdvise(IPC_BENCHMARK_ITEM
);
114 m_conn
->Disconnect();
120 PokeAdviseConn
*Get() const { return m_conn
; }
123 PokeAdviseClient
*m_client
;
124 PokeAdviseConn
*m_conn
;
127 DECLARE_NO_COPY_CLASS(PokeAdvisePersistentConnection
)
130 PokeAdvisePersistentConnection
*theConnection
= NULL
;
134 theConnection
= new PokeAdvisePersistentConnection
;
135 if ( !theConnection
->Get() )
137 delete theConnection
;
138 theConnection
= NULL
;
147 delete theConnection
;
150 } // anonymous namespace
152 BENCHMARK_FUNC_WITH_INIT(IPCPokeAdvise
, ConnInit
, ConnDone
)
156 PokeAdviseConn
* const conn
= theConnection
->Get();
158 const wxString
s(1024, '@');
160 if ( !conn
->Poke(IPC_BENCHMARK_ITEM
, s
) )
163 while ( !conn
->GotAdvised() )
166 if ( conn
->GetItem() != s
)