KiCad PCB EDA Suite
eda_dde.cpp File Reference
#include <fctsys.h>
#include <eda_dde.h>
#include <draw_frame.h>
#include <id.h>
#include <common.h>
#include <macros.h>

Go to the source code of this file.

Macros

#define IPC_BUF_SIZE   4096
 

Functions

static const wxString HOSTNAME (wxT("localhost"))
 
wxSocketServer * CreateServer (wxWindow *window, int service, bool local)
 
bool SendCommand (int service, const char *cmdline)
 

Variables

static char client_ipc_buffer [IPC_BUF_SIZE]
 

Macro Definition Documentation

#define IPC_BUF_SIZE   4096

Definition at line 39 of file eda_dde.cpp.

Referenced by EDA_DRAW_FRAME::OnSockRequest().

Function Documentation

wxSocketServer* CreateServer ( wxWindow *  window,
int  service,
bool  local 
)

Definition at line 49 of file eda_dde.cpp.

References HOSTNAME(), and ID_EDA_SOCKET_EVENT_SERV.

Referenced by SCH::IFACE::CreateWindow(), and PCB::IFACE::CreateWindow().

50 {
51  wxIPV4address addr;
52 
53  // Set the port number
54  addr.Service( service );
55 
56  // Listen on localhost only if requested
57  if( local )
58  addr.Hostname( HOSTNAME );
59 
60  wxSocketServer* server = new wxSocketServer( addr );
61 
62  if( server )
63  {
64  server->SetNotify( wxSOCKET_CONNECTION_FLAG );
65  server->SetEventHandler( *window, ID_EDA_SOCKET_EVENT_SERV );
66  server->Notify( true );
67  }
68 
69  return server;
70 }
static const wxString HOSTNAME(wxT("localhost"))
static const wxString HOSTNAME ( wxT("localhost")  )
static

Referenced by CreateServer(), and SendCommand().

bool SendCommand ( int  service,
const char *  cmdline 
)

Definition at line 134 of file eda_dde.cpp.

References HOSTNAME().

Referenced by CVPCB_MAINFRAME::SendMessageToEESCHEMA(), PCB_EDIT_FRAME::SendMessageToEESCHEMA(), and SCH_EDIT_FRAME::SendMessageToPCBNEW().

135 {
136  wxSocketClient* sock_client;
137  bool success = false;
138  wxIPV4address addr;
139 
140  // Create a connexion
141  addr.Hostname( HOSTNAME );
142  addr.Service( service );
143 
144  // Mini-tutorial for Connect() :-)
145  // (JP CHARRAS Note: see wxWidgets: sockets/client.cpp sample)
146  // ---------------------------
147  //
148  // There are two ways to use Connect(): blocking and non-blocking,
149  // depending on the value passed as the 'wait' (2nd) parameter.
150  //
151  // Connect(addr, true) will wait until the connection completes,
152  // returning true on success and false on failure. This call blocks
153  // the GUI (this might be changed in future releases to honor the
154  // wxSOCKET_BLOCK flag).
155  //
156  // Connect(addr, false) will issue a nonblocking connection request
157  // and return immediately. If the return value is true, then the
158  // connection has been already successfully established. If it is
159  // false, you must wait for the request to complete, either with
160  // WaitOnConnect() or by watching wxSOCKET_CONNECTION / LOST
161  // events (please read the documentation).
162  //
163  // WaitOnConnect() itself never blocks the GUI (this might change
164  // in the future to honor the wxSOCKET_BLOCK flag). This call will
165  // return false on timeout, or true if the connection request
166  // completes, which in turn might mean:
167  //
168  // a) That the connection was successfully established
169  // b) That the connection request failed (for example, because
170  // it was refused by the peer.
171  //
172  // Use IsConnected() to distinguish between these two.
173  //
174  // So, in a brief, you should do one of the following things:
175  //
176  // For blocking Connect:
177  //
178  // bool success = client->Connect(addr, true);
179  //
180  // For nonblocking Connect:
181  //
182  // client->Connect(addr, false);
183  //
184  // bool waitmore = true;
185  // while (! client->WaitOnConnect(seconds, millis) && waitmore )
186  // {
187  // // possibly give some feedback to the user,
188  // // update waitmore if needed.
189  // }
190  // bool success = client->IsConnected();
191  //
192  // And that's all :-)
193 
194  sock_client = new wxSocketClient();
195  sock_client->SetTimeout( 2 ); // Time out in Seconds
196  sock_client->Connect( addr, false );
197  sock_client->WaitOnConnect( 0, 100 );
198 
199  if( sock_client->Ok() && sock_client->IsConnected() )
200  {
201  success = true;
202  sock_client->SetFlags( wxSOCKET_NOWAIT /*wxSOCKET_WAITALL*/ );
203  sock_client->Write( cmdline, strlen( cmdline ) );
204  }
205 
206  sock_client->Close();
207  sock_client->Destroy();
208  return success;
209 }
static const wxString HOSTNAME(wxT("localhost"))

Variable Documentation

char client_ipc_buffer[IPC_BUF_SIZE]
static

Definition at line 40 of file eda_dde.cpp.