connection.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: connection.h
  3. // Purpose: DDE sample: MyConnection class
  4. // Author: Vadim Zeitlin
  5. // Created: 2008-02-11 (extracted from client.cpp)
  6. // Copyright: (c) 1999 Julian Smart
  7. // 2008 Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_SAMPLE_IPC_CONNECTION_H_
  11. #define _WX_SAMPLE_IPC_CONNECTION_H_
  12. // This simple connection class adds logging of all operations
  13. class MyConnectionBase : public wxConnection
  14. {
  15. protected:
  16. void Log(const wxString& command,
  17. const wxString& topic,
  18. const wxString& item,
  19. const void *data,
  20. size_t size,
  21. wxIPCFormat format)
  22. {
  23. wxString s;
  24. if (topic.IsEmpty() && item.IsEmpty())
  25. s.Printf("%s(", command.c_str());
  26. else if (topic.IsEmpty())
  27. s.Printf("%s(item=\"%s\",", command.c_str(), item.c_str());
  28. else if (item.IsEmpty())
  29. s.Printf("%s(topic=\"%s\",", command.c_str(), topic.c_str());
  30. else
  31. s.Printf("%s(topic=\"%s\",item=\"%s\",", command.c_str(), topic.c_str(), item.c_str());
  32. switch (format)
  33. {
  34. case wxIPC_TEXT:
  35. s += wxString(static_cast<const char *>(data), size);
  36. break;
  37. #if wxUSE_UNICODE
  38. case wxIPC_UNICODETEXT:
  39. s += wxString(static_cast<const wchar_t *>(data), size);
  40. break;
  41. #endif // wxUSE_UNICODE
  42. case wxIPC_UTF8TEXT:
  43. s += wxString::FromUTF8(static_cast<const char *>(data), size);
  44. break;
  45. case wxIPC_PRIVATE:
  46. if ( size == 3 )
  47. {
  48. const char *bytes = static_cast<const char *>(data);
  49. s << '"' << bytes[0] << bytes[1] << bytes[2] << '"';
  50. }
  51. else
  52. {
  53. s << "\"???\"";
  54. }
  55. break;
  56. case wxIPC_INVALID:
  57. s += "[invalid data]";
  58. break;
  59. default:
  60. s += "[unknown data]";
  61. break;
  62. }
  63. wxLogMessage("%s,%d)", s, size);
  64. }
  65. };
  66. #endif // _WX_SAMPLE_IPC_CONNECTION_H_