X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/39d580f7dcc48a85d092f6088f8c978a18db5a97..ee682a94cb9ea835c9b74a12f17b0fb63f43dcce:/samples/ipc/server.cpp diff --git a/samples/ipc/server.cpp b/samples/ipc/server.cpp index f278b704e8..1f4a3b63fe 100644 --- a/samples/ipc/server.cpp +++ b/samples/ipc/server.cpp @@ -57,7 +57,6 @@ END_EVENT_TABLE() // global variables // ---------------------------------------------------------------------------- -char ipc_buffer[4000]; MyConnection *the_connection = NULL; // ============================================================================ @@ -74,7 +73,7 @@ bool MyApp::OnInit() (new MyFrame(NULL, "Server"))->Show(TRUE); // service name (DDE classes) or port number (TCP/IP based classes) - wxString service = "4242"; + wxString service = IPC_SERVICE; if (argc > 1) service = argv[1]; @@ -134,9 +133,12 @@ void MyFrame::OnListBoxClick(wxCommandEvent& WXUNUSED(event)) if (listBox) { wxString value = listBox->GetStringSelection(); + + /* Because the_connection only holds one connection, in this sample only + one connection can receive advise messages */ if (the_connection) { - the_connection->Advise("Item", (wxChar *)value.c_str()); + the_connection->Advise(IPC_ADVISE_NAME, (wxChar *)value.c_str()); } } } @@ -161,6 +163,14 @@ IPCDialogBox::IPCDialogBox(wxWindow *parent, const wxString& title, Fit(); } +IPCDialogBox::~IPCDialogBox( ) +{ + // wxWindows exit code destroys dialog before destroying the connection in + // OnExit, so make sure connection won't try to delete the dialog later. + if (m_connection) + m_connection->dialog = NULL; +} + void IPCDialogBox::OnQuit(wxCommandEvent& event) { m_connection->Disconnect(); @@ -173,18 +183,19 @@ void IPCDialogBox::OnQuit(wxCommandEvent& event) wxConnectionBase *MyServer::OnAcceptConnection(const wxString& topic) { - if (strcmp(topic, "STDIO") != 0 && strcmp(topic, "IPC TEST") == 0) - return new MyConnection(ipc_buffer, WXSIZEOF(ipc_buffer)); - else - return NULL; + if ( topic == IPC_TOPIC ) + return new MyConnection(); + + // unknown topic + return NULL; } // ---------------------------------------------------------------------------- // MyConnection // ---------------------------------------------------------------------------- -MyConnection::MyConnection(char *buf, int size) - : wxConnection(buf, size) +MyConnection::MyConnection() + : wxConnection() { dialog = new IPCDialogBox(wxTheApp->GetTopWindow(), "Connection", wxPoint(100, 100), wxSize(500, 500), this); @@ -196,7 +207,11 @@ MyConnection::~MyConnection() { if (the_connection) { - dialog->Destroy(); + if (dialog) + { + dialog->m_connection = NULL; + dialog->Destroy(); + } the_connection = NULL; } } @@ -206,7 +221,7 @@ bool MyConnection::OnExecute(const wxString& WXUNUSED(topic), int WXUNUSED(size), wxIPCFormat WXUNUSED(format)) { - wxLogStatus("Execute command: %s", data); + wxLogStatus(wxT("Execute command: %s"), data); return TRUE; } @@ -216,7 +231,7 @@ bool MyConnection::OnPoke(const wxString& WXUNUSED(topic), int WXUNUSED(size), wxIPCFormat WXUNUSED(format)) { - wxLogStatus("Poke command: %s = %s", item.c_str(), data); + wxLogStatus(wxT("Poke command: %s = %s"), item.c_str(), data); return TRUE; }