contents up previous next

wxconnection

a wxconnection object represents the connection between a client and a server. it is created by making a connection using a wxclient object, or by the acceptance of a connection by a wxserver object. the bulk of a dde-like (dynamic data exchange) conversation is controlled by calling members in a wxconnection object or by overriding its members. the actual dde-based implementation using wxddeconnection is available on windows only, but a platform-independent, socket-based version of this api is available using wxtcpconnection, which has the same api.

an application should normally derive a new connection class from wxconnection, in order to override the communication event handlers to do something interesting.

derived from

wxconnectionbase
wxobject

include files

<wx/ipc.h>

types

wxipcformat is defined as follows:

enum wxipcformat
{
  wxipc_invalid =          0,
  wxipc_text =             1,  /* cf_text */
  wxipc_bitmap =           2,  /* cf_bitmap */
  wxipc_metafile =         3,  /* cf_metafilepict */
  wxipc_sylk =             4,
  wxipc_dif =              5,
  wxipc_tiff =             6,
  wxipc_oemtext =          7,  /* cf_oemtext */
  wxipc_dib =              8,  /* cf_dib */
  wxipc_palette =          9,
  wxipc_pendata =          10,
  wxipc_riff =             11,
  wxipc_wave =             12,
  wxipc_unicodetext =      13,
  wxipc_enhmetafile =      14,
  wxipc_filename =         15, /* cf_hdrop */
  wxipc_locale =           16,
  wxipc_private =          20
};
see also

wxclient, wxserver, interprocess communications overview

members

wxconnection::wxconnection
wxconnection::advise
wxconnection::execute
wxconnection::disconnect
wxconnection::onadvise
wxconnection::ondisconnect
wxconnection::onexecute
wxconnection::onpoke
wxconnection::onrequest
wxconnection::onstartadvise
wxconnection::onstopadvise
wxconnection::poke
wxconnection::request
wxconnection::startadvise
wxconnection::stopadvise


wxconnection::wxconnection

wxconnection()

wxconnection(char* buffer, int size)

constructs a connection object. if no user-defined connection object is to be derived from wxconnection, then the constructor should not be called directly, since the default connection object will be provided on requesting (or accepting) a connection. however, if the user defines his or her own derived connection object, the wxserver::onacceptconnection and/or wxclient::onmakeconnection members should be replaced by functions which construct the new connection object.

if the arguments of the wxconnection constructor are void then the wxconnection object manages its own connection buffer, allocating memory as needed. a programmer-supplied buffer cannot be increased if necessary, and the program will assert if it is not large enough. the programmer-supplied buffer is included mainly for backwards compatibility.


wxconnection::advise

bool advise(const wxstring& item, char* data, int size = -1, wxipcformat format = wxcf_text)

called by the server application to advise the client of a change in the data associated with the given item. causes the client connection's wxconnection::onadvise member to be called. returns true if successful.


wxconnection::execute

bool execute(char* data, int size = -1, wxipcformat format = wxcf_text)

called by the client application to execute a command on the server. can also be used to transfer arbitrary data to the server (similar to wxconnection::poke in that respect). causes the server connection's wxconnection::onexecute member to be called. returns true if successful.


wxconnection::disconnect

bool disconnect()

called by the client or server application to disconnect from the other program; it causes the wxconnection::ondisconnect message to be sent to the corresponding connection object in the other program. returns true if successful or already disconnected. the application that calls disconnect must explicitly delete its side of the connection.


wxconnection::onadvise

virtual bool onadvise(const wxstring& topic, const wxstring& item, char* data, int size, wxipcformat format)

message sent to the client application when the server notifies it of a change in the data associated with the given item, using advise.


wxconnection::ondisconnect

virtual bool ondisconnect()

message sent to the client or server application when the other application notifies it to end the connection. the default behaviour is to delete the connection object and return true, so applications should generally override ondisconnect (finally calling the inherited method as well) so that they know the connection object is no longer available.


wxconnection::onexecute

virtual bool onexecute(const wxstring& topic, char* data, int size, wxipcformat format)

message sent to the server application when the client notifies it to execute the given data, using execute. note that there is no item associated with this message.


wxconnection::onpoke

virtual bool onpoke(const wxstring& topic, const wxstring& item, char* data, int size, wxipcformat format)

message sent to the server application when the client notifies it to accept the given data.


wxconnection::onrequest

virtual char* onrequest(const wxstring& topic, const wxstring& item, int *size, wxipcformat format)

message sent to the server application when the client calls wxconnection::request. the server's onrequest method should respond by returning a character string, or null to indicate no data, and setting *size. the character string must of course persist after the call returns.


wxconnection::onstartadvise

virtual bool onstartadvise(const wxstring& topic, const wxstring& item)

message sent to the server application by the client, when the client wishes to start an 'advise loop' for the given topic and item. the server can refuse to participate by returning false.


wxconnection::onstopadvise

virtual bool onstopadvise(const wxstring& topic, const wxstring& item)

message sent to the server application by the client, when the client wishes to stop an 'advise loop' for the given topic and item. the server can refuse to stop the advise loop by returning false, although this doesn't have much meaning in practice.


wxconnection::poke

bool poke(const wxstring& item, char* data, int size = -1, wxipcformat format = wxcf_text)

called by the client application to poke data into the server. can be used to transfer arbitrary data to the server. causes the server connection's wxconnection::onpoke member to be called. if size is -1 the size is computed from the string length of data.

returns true if successful.


wxconnection::request

char* request(const wxstring& item, int *size, wxipcformat format = wxipc_text)

called by the client application to request data from the server. causes the server connection's wxconnection::onrequest member to be called. size may be null or a pointer to a variable to receive the size of the requested item.

returns a character string (actually a pointer to the connection's buffer) if successful, null otherwise. this buffer does not need to be deleted.


wxconnection::startadvise

bool startadvise(const wxstring& item)

called by the client application to ask if an advise loop can be started with the server. causes the server connection's wxconnection::onstartadvise member to be called. returns true if the server okays it, false otherwise.


wxconnection::stopadvise

bool stopadvise(const wxstring& item)

called by the client application to ask if an advise loop can be stopped. causes the server connection's wxconnection::onstopadvise member to be called. returns true if the server okays it, false otherwise.