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 (
const wxString& WXUNUSED ( topic ),
const wxString& item,
wxChar *data,
int size,
wxIPCFormat WXUNUSED ( format ) )
const wxString& WXUNUSED ( topic )
, const wxString& item
#if wxCHECK_VERSION(2,9,0)
, const void *data
, size_t size
#else
, wxChar *data
, int size
#endif
, wxIPCFormat WXUNUSED ( format )
)
{
if ( !wxTheApp )
return false;
@ -90,7 +96,18 @@ wxConnectionBase *MyClient::OnMakeConnection()
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;
}

View File

@ -40,7 +40,17 @@ class MyServerConnection : public wxConnection
public:
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 );
};
@ -48,7 +58,16 @@ class MyClientConnection: public wxConnection
{
public:
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();
};

View File

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

View File

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