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 licence
9 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/evtloop.h"
15 // do this before including wx/ipc.h under Windows to use TCP even there
16 #define wxUSE_DDE_FOR_IPC 0
18 #include "../../samples/ipc/ipcsetup.h"
23 class PokeAdviseConn
: public wxConnection
26 PokeAdviseConn() { m_gotAdvised
= false; }
38 const wxString
& GetItem() const { return m_item
; }
40 virtual bool OnAdvise(const wxString
& topic
,
48 if ( topic
!= IPC_BENCHMARK_TOPIC
||
49 item
!= IPC_BENCHMARK_ITEM
||
50 !IsTextFormat(format
) )
56 m_item
= GetTextFromData(data
, size
, format
);
65 DECLARE_NO_COPY_CLASS(PokeAdviseConn
)
68 class PokeAdviseClient
: public wxClient
71 // provide a convenient helper taking care of connecting to the right
72 // server/service/topic and returning the connection of the derived type
73 // (or NULL if we failed to connect)
74 PokeAdviseConn
*Connect()
76 wxString host
= Bench::GetStringParameter();
81 int port
= Bench::GetNumericParameter();
83 service
= IPC_SERVICE
;
85 service
.Printf("%d", port
);
87 return static_cast<PokeAdviseConn
*>(
88 MakeConnection(host
, service
, IPC_BENCHMARK_TOPIC
));
92 // override base class virtual to use a custom connection class
93 virtual wxConnectionBase
*OnMakeConnection()
95 return new PokeAdviseConn
;
99 class PokeAdvisePersistentConnection
102 PokeAdvisePersistentConnection()
104 m_client
= new PokeAdviseClient
;
105 m_conn
= m_client
->Connect();
107 m_conn
->StartAdvise(IPC_BENCHMARK_ITEM
);
110 ~PokeAdvisePersistentConnection()
114 m_conn
->StopAdvise(IPC_BENCHMARK_ITEM
);
115 m_conn
->Disconnect();
121 PokeAdviseConn
*Get() const { return m_conn
; }
124 PokeAdviseClient
*m_client
;
125 PokeAdviseConn
*m_conn
;
128 DECLARE_NO_COPY_CLASS(PokeAdvisePersistentConnection
)
131 PokeAdvisePersistentConnection
*theConnection
= NULL
;
135 theConnection
= new PokeAdvisePersistentConnection
;
136 if ( !theConnection
->Get() )
138 delete theConnection
;
139 theConnection
= NULL
;
148 delete theConnection
;
151 } // anonymous namespace
153 BENCHMARK_FUNC_WITH_INIT(IPCPokeAdvise
, ConnInit
, ConnDone
)
157 PokeAdviseConn
* const conn
= theConnection
->Get();
159 const wxString
s(1024, '@');
161 if ( !conn
->Poke(IPC_BENCHMARK_ITEM
, s
) )
164 while ( !conn
->GotAdvised() )
167 if ( conn
->GetItem() != s
)