Made single instance checking work for wxWidgets 2.9

This commit is contained in:
Zane U. Ji 2013-10-15 22:55:28 +08:00
parent af3e0d751a
commit ef4c10ce0b
4 changed files with 47 additions and 16 deletions

View File

@ -46,11 +46,17 @@ MyServerConnection::~MyServerConnection()
} }
bool MyServerConnection::OnPoke ( bool MyServerConnection::OnPoke (
const wxString& WXUNUSED ( topic ), const wxString& WXUNUSED ( topic )
const wxString& item, , const wxString& item
wxChar *data, #if wxCHECK_VERSION(2,9,0)
int size, , const void *data
wxIPCFormat WXUNUSED ( format ) ) , size_t size
#else
, wxChar *data
, int size
#endif
, wxIPCFormat WXUNUSED ( format )
)
{ {
if ( !wxTheApp ) if ( !wxTheApp )
return false; return false;
@ -90,7 +96,18 @@ wxConnectionBase *MyClient::OnMakeConnection()
return new MyClientConnection; return new MyClientConnection;
} }
bool MyClientConnection::OnAdvise ( const wxString& WXUNUSED ( topic ), const wxString& WXUNUSED ( item ), wxChar *data, int WXUNUSED ( size ), wxIPCFormat WXUNUSED ( format ) ) bool MyClientConnection::OnAdvise (
const wxString& WXUNUSED ( topic )
, const wxString& WXUNUSED ( item )
#if wxCHECK_VERSION(2,9,0)
, const void * WXUNUSED ( data )
, size_t WXUNUSED ( size )
#else
, wxChar * WXUNUSED ( data )
, int WXUNUSED ( size )
#endif
, wxIPCFormat WXUNUSED ( format )
)
{ {
return true; return true;
} }

View File

@ -40,7 +40,17 @@ class MyServerConnection : public wxConnection
public: public:
MyServerConnection(); MyServerConnection();
~MyServerConnection(); ~MyServerConnection();
bool OnPoke ( const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format ); bool OnPoke ( const wxString& topic
, const wxString& item
#if wxCHECK_VERSION(2,9,0)
, const void *data
, size_t size
#else
, wxChar *data
, int size
#endif
, wxIPCFormat format
);
bool OnStartAdvise ( const wxString& topic, const wxString& item ); bool OnStartAdvise ( const wxString& topic, const wxString& item );
}; };
@ -48,7 +58,16 @@ class MyClientConnection: public wxConnection
{ {
public: public:
MyClientConnection(); MyClientConnection();
bool OnAdvise ( const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format ); bool OnAdvise ( const wxString& topic
, const wxString& item
#if wxCHECK_VERSION(2,9,0)
, const void *data
, size_t size
#else
, wxChar *data
, int size
#endif
, wxIPCFormat format );
bool OnDisconnect(); bool OnDisconnect();
}; };

View File

@ -205,8 +205,6 @@ IMPLEMENT_APP ( MyApp)
MyApp::MyApp() MyApp::MyApp()
: checker ( NULL ) : checker ( NULL )
, server ( NULL ) , server ( NULL )
, client ( NULL )
, connection ( NULL )
, singleInstanceCheck ( false ) , singleInstanceCheck ( false )
, lang ( 0 ) , lang ( 0 )
#if defined(__WXMSW__) && !wxCHECK_VERSION(2,9,0) #if defined(__WXMSW__) && !wxCHECK_VERSION(2,9,0)
@ -227,7 +225,6 @@ MyApp::~MyApp()
delete checker; delete checker;
delete server; delete server;
delete connection;
} }
bool MyApp::OnInit() bool MyApp::OnInit()
@ -337,9 +334,9 @@ bool MyApp::OnInit()
while ( checker->IsAnotherRunning() ) while ( checker->IsAnotherRunning() )
{ {
// attempt calling server // attempt calling server
client = new MyClient(); MyClient client;
connection = ( MyClientConnection * ) MyClientConnection *connection = ( MyClientConnection * )
client->MakeConnection ( hostName, service, IPC_TOPIC ); client.MakeConnection ( hostName, service, IPC_TOPIC );
if ( !connection || !connection->StartAdvise ( IPC_ADVISE_NAME ) ) if ( !connection || !connection->StartAdvise ( IPC_ADVISE_NAME ) )
break; break;
else else

View File

@ -185,8 +185,6 @@ class MyApp : public wxApp
private: private:
wxSingleInstanceChecker *checker; wxSingleInstanceChecker *checker;
MyServer *server; MyServer *server;
MyClient *client;
MyClientConnection *connection;
bool singleInstanceCheck; bool singleInstanceCheck;
int lang; int lang;
std::auto_ptr<wxFileConfig> config; std::auto_ptr<wxFileConfig> config;