dialup.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/dialup.h
  3. // Purpose: Network related wxWidgets classes and functions
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 07.07.99
  7. // Copyright: (c) Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_DIALUP_H
  11. #define _WX_DIALUP_H
  12. #if wxUSE_DIALUP_MANAGER
  13. #include "wx/event.h"
  14. // ----------------------------------------------------------------------------
  15. // misc
  16. // ----------------------------------------------------------------------------
  17. class WXDLLIMPEXP_FWD_BASE wxArrayString;
  18. #define WXDIALUP_MANAGER_DEFAULT_BEACONHOST wxT("www.yahoo.com")
  19. // ----------------------------------------------------------------------------
  20. // A class which groups functions dealing with connecting to the network from a
  21. // workstation using dial-up access to the net. There is at most one instance
  22. // of this class in the program accessed via GetDialUpManager().
  23. // ----------------------------------------------------------------------------
  24. /* TODO
  25. *
  26. * 1. more configurability for Unix: i.e. how to initiate the connection, how
  27. * to check for online status, &c.
  28. * 2. a function to enumerate all connections (ISPs) and show a dialog in
  29. * Dial() allowing to choose between them if no ISP given
  30. * 3. add an async version of dialing functions which notify the caller about
  31. * the progress (or may be even start another thread to monitor it)
  32. * 4. the static creation/accessor functions are not MT-safe - but is this
  33. * really crucial? I think we may suppose they're always called from the
  34. * main thread?
  35. */
  36. class WXDLLIMPEXP_CORE wxDialUpManager
  37. {
  38. public:
  39. // this function should create and return the object of the
  40. // platform-specific class derived from wxDialUpManager. It's implemented
  41. // in the platform-specific source files.
  42. static wxDialUpManager *Create();
  43. // could the dialup manager be initialized correctly? If this function
  44. // returns false, no other functions will work neither, so it's a good idea
  45. // to call this function and check its result before calling any other
  46. // wxDialUpManager methods
  47. virtual bool IsOk() const = 0;
  48. // virtual dtor for any base class
  49. virtual ~wxDialUpManager() { }
  50. // operations
  51. // ----------
  52. // fills the array with the names of all possible values for the first
  53. // parameter to Dial() on this machine and returns their number (may be 0)
  54. virtual size_t GetISPNames(wxArrayString& names) const = 0;
  55. // dial the given ISP, use username and password to authentificate
  56. //
  57. // if no nameOfISP is given, the function will select the default one
  58. //
  59. // if no username/password are given, the function will try to do without
  60. // them, but will ask the user if really needed
  61. //
  62. // if async parameter is false, the function waits until the end of dialing
  63. // and returns true upon successful completion.
  64. // if async is true, the function only initiates the connection and returns
  65. // immediately - the result is reported via events (an event is sent
  66. // anyhow, but if dialing failed it will be a DISCONNECTED one)
  67. virtual bool Dial(const wxString& nameOfISP = wxEmptyString,
  68. const wxString& username = wxEmptyString,
  69. const wxString& password = wxEmptyString,
  70. bool async = true) = 0;
  71. // returns true if (async) dialing is in progress
  72. virtual bool IsDialing() const = 0;
  73. // cancel dialing the number initiated with Dial(async = true)
  74. // NB: this won't result in DISCONNECTED event being sent
  75. virtual bool CancelDialing() = 0;
  76. // hang up the currently active dial up connection
  77. virtual bool HangUp() = 0;
  78. // online status
  79. // -------------
  80. // returns true if the computer has a permanent network connection (i.e. is
  81. // on a LAN) and so there is no need to use Dial() function to go online
  82. //
  83. // NB: this functions tries to guess the result and it is not always
  84. // guaranteed to be correct, so it's better to ask user for
  85. // confirmation or give him a possibility to override it
  86. virtual bool IsAlwaysOnline() const = 0;
  87. // returns true if the computer is connected to the network: under Windows,
  88. // this just means that a RAS connection exists, under Unix we check that
  89. // the "well-known host" (as specified by SetWellKnownHost) is reachable
  90. virtual bool IsOnline() const = 0;
  91. // sometimes the built-in logic for determining the online status may fail,
  92. // so, in general, the user should be allowed to override it. This function
  93. // allows to forcefully set the online status - whatever our internal
  94. // algorithm may think about it.
  95. virtual void SetOnlineStatus(bool isOnline = true) = 0;
  96. // set misc wxDialUpManager options
  97. // --------------------------------
  98. // enable automatical checks for the connection status and sending of
  99. // wxEVT_DIALUP_CONNECTED/wxEVT_DIALUP_DISCONNECTED events. The interval
  100. // parameter is only for Unix where we do the check manually: under
  101. // Windows, the notification about the change of connection status is
  102. // instantenous.
  103. //
  104. // Returns false if couldn't set up automatic check for online status.
  105. virtual bool EnableAutoCheckOnlineStatus(size_t nSeconds = 60) = 0;
  106. // disable automatic check for connection status change - notice that the
  107. // wxEVT_DIALUP_XXX events won't be sent any more neither.
  108. virtual void DisableAutoCheckOnlineStatus() = 0;
  109. // additional Unix-only configuration
  110. // ----------------------------------
  111. // under Unix, the value of well-known host is used to check whether we're
  112. // connected to the internet. It's unused under Windows, but this function
  113. // is always safe to call. The default value is www.yahoo.com.
  114. virtual void SetWellKnownHost(const wxString& hostname,
  115. int portno = 80) = 0;
  116. // Sets the commands to start up the network and to hang up again. Used by
  117. // the Unix implementations only.
  118. virtual void
  119. SetConnectCommand(const wxString& commandDial = wxT("/usr/bin/pon"),
  120. const wxString& commandHangup = wxT("/usr/bin/poff")) = 0;
  121. };
  122. // ----------------------------------------------------------------------------
  123. // wxDialUpManager events
  124. // ----------------------------------------------------------------------------
  125. class WXDLLIMPEXP_FWD_CORE wxDialUpEvent;
  126. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIALUP_CONNECTED, wxDialUpEvent );
  127. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIALUP_DISCONNECTED, wxDialUpEvent );
  128. // the event class for the dialup events
  129. class WXDLLIMPEXP_CORE wxDialUpEvent : public wxEvent
  130. {
  131. public:
  132. wxDialUpEvent(bool isConnected, bool isOwnEvent) : wxEvent(isOwnEvent)
  133. {
  134. SetEventType(isConnected ? wxEVT_DIALUP_CONNECTED
  135. : wxEVT_DIALUP_DISCONNECTED);
  136. }
  137. // is this a CONNECTED or DISCONNECTED event?
  138. bool IsConnectedEvent() const
  139. { return GetEventType() == wxEVT_DIALUP_CONNECTED; }
  140. // does this event come from wxDialUpManager::Dial() or from some external
  141. // process (i.e. does it result from our own attempt to establish the
  142. // connection)?
  143. bool IsOwnEvent() const { return m_id != 0; }
  144. // implement the base class pure virtual
  145. virtual wxEvent *Clone() const { return new wxDialUpEvent(*this); }
  146. private:
  147. wxDECLARE_NO_ASSIGN_CLASS(wxDialUpEvent);
  148. };
  149. // the type of dialup event handler function
  150. typedef void (wxEvtHandler::*wxDialUpEventFunction)(wxDialUpEvent&);
  151. #define wxDialUpEventHandler(func) \
  152. wxEVENT_HANDLER_CAST(wxDialUpEventFunction, func)
  153. // macros to catch dialup events
  154. #define EVT_DIALUP_CONNECTED(func) \
  155. wx__DECLARE_EVT0(wxEVT_DIALUP_CONNECTED, wxDialUpEventHandler(func))
  156. #define EVT_DIALUP_DISCONNECTED(func) \
  157. wx__DECLARE_EVT0(wxEVT_DIALUP_DISCONNECTED, wxDialUpEventHandler(func))
  158. #endif // wxUSE_DIALUP_MANAGER
  159. #endif // _WX_DIALUP_H