dialup.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dialup.h
  3. // Purpose: interface of wxDialUpManager
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxDialUpManager
  9. This class encapsulates functions dealing with verifying the connection
  10. status of the workstation (connected to the Internet via a direct
  11. connection, connected through a modem or not connected at all) and to
  12. establish this connection if possible/required (i.e. in the case of the
  13. modem).
  14. The program may also wish to be notified about the change in the connection
  15. status (for example, to perform some action when the user connects to the
  16. network the next time or, on the contrary, to stop receiving data from the
  17. net when the user hangs up the modem). For this, you need to use one of the
  18. event macros described below.
  19. This class is different from other wxWidgets classes in that there is at
  20. most one instance of this class in the program accessed via Create() and
  21. you can't create the objects of this class directly.
  22. @beginEventEmissionTable{wxDialUpEvent}
  23. @event{EVT_DIALUP_CONNECTED(func)}
  24. A connection with the network was established.
  25. @event{EVT_DIALUP_DISCONNECTED(func)}
  26. The connection with the network was lost.
  27. @endEventTable
  28. @library{wxcore}
  29. @category{net}
  30. @see @ref page_samples_dialup, wxDialUpEvent
  31. */
  32. class wxDialUpManager
  33. {
  34. public:
  35. /**
  36. Destructor.
  37. */
  38. virtual ~wxDialUpManager();
  39. /**
  40. Cancel dialing the number initiated with Dial() with async parameter
  41. equal to @true.
  42. @note This won't result in a DISCONNECTED event being sent.
  43. @see IsDialing()
  44. */
  45. virtual bool CancelDialing() = 0;
  46. /**
  47. This function should create and return the object of the
  48. platform-specific class derived from wxDialUpManager. You should delete
  49. the pointer when you are done with it.
  50. */
  51. static wxDialUpManager* Create();
  52. /**
  53. Dial the given ISP, use @a username and @a password to authenticate.
  54. The parameters are only used under Windows currently, for Unix you
  55. should use SetConnectCommand() to customize this functions behaviour.
  56. If no @a nameOfISP is given, the function will select the default one
  57. (proposing the user to choose among all connections defined on this
  58. machine) and if no username and/or password are given, the function
  59. will try to do without them, but will ask the user if really needed.
  60. If @a async parameter is @false, the function waits until the end of
  61. dialing and returns @true upon successful completion.
  62. If @a async is @true, the function only initiates the connection and
  63. returns immediately - the result is reported via events (an event is
  64. sent anyhow, but if dialing failed it will be a DISCONNECTED one).
  65. */
  66. virtual bool Dial(const wxString& nameOfISP = wxEmptyString,
  67. const wxString& username = wxEmptyString,
  68. const wxString& password = wxEmptyString,
  69. bool async = true) = 0;
  70. /**
  71. Disable automatic check for connection status change - notice that the
  72. @c wxEVT_DIALUP_XXX events won't be sent any more neither.
  73. */
  74. virtual void DisableAutoCheckOnlineStatus() = 0;
  75. /**
  76. Enable automatic checks for the connection status and sending of
  77. @c wxEVT_DIALUP_CONNECTED/wxEVT_DIALUP_DISCONNECTED events. The interval
  78. parameter is only for Unix where we do the check manually and specifies
  79. how often should we repeat the check (each minute by default). Under
  80. Windows, the notification about the change of connection status is sent
  81. by the system and so we don't do any polling and this parameter is
  82. ignored.
  83. @return @false if couldn't set up automatic check for online status.
  84. */
  85. virtual bool EnableAutoCheckOnlineStatus(size_t nSeconds = 60) = 0;
  86. /**
  87. This function is only implemented under Windows.
  88. Fills the array with the names of all possible values for the first
  89. parameter to Dial() on this machine and returns their number (may be
  90. 0).
  91. */
  92. virtual size_t GetISPNames(wxArrayString& names) const = 0;
  93. /**
  94. Hang up the currently active dial up connection.
  95. */
  96. virtual bool HangUp() = 0;
  97. /**
  98. Returns @true if the computer has a permanent network connection (i.e.\
  99. is on a LAN) and so there is no need to use Dial() function to go
  100. online.
  101. @note This function tries to guess the result and it is not always
  102. guaranteed to be correct, so it is better to ask user for
  103. confirmation or give him a possibility to override it.
  104. */
  105. virtual bool IsAlwaysOnline() const = 0;
  106. /**
  107. Returns @true if (async) dialing is in progress.
  108. @see Dial()
  109. */
  110. virtual bool IsDialing() const = 0;
  111. /**
  112. Returns @true if the dialup manager was initialized correctly. If this
  113. function returns @false, no other functions will work neither, so it is
  114. a good idea to call this function and check its result before calling
  115. any other wxDialUpManager methods.
  116. */
  117. virtual bool IsOk() const = 0;
  118. /**
  119. Returns @true if the computer is connected to the network: under
  120. Windows, this just means that a RAS connection exists, under Unix we
  121. check that the "well-known host" (as specified by SetWellKnownHost())
  122. is reachable.
  123. */
  124. virtual bool IsOnline() const = 0;
  125. /**
  126. This method is for Unix only.
  127. Sets the commands to start up the network and to hang up again.
  128. */
  129. virtual void SetConnectCommand(const wxString& commandDial = "/usr/bin/pon",
  130. const wxString& commandHangup = "/usr/bin/poff") = 0;
  131. /**
  132. Sometimes the built-in logic for determining the online status may
  133. fail, so, in general, the user should be allowed to override it. This
  134. function allows to forcefully set the online status - whatever our
  135. internal algorithm may think about it.
  136. @see IsOnline()
  137. */
  138. virtual void SetOnlineStatus(bool isOnline = true) = 0;
  139. /**
  140. This method is for Unix only.
  141. Under Unix, the value of well-known host is used to check whether we're
  142. connected to the internet. It is unused under Windows, but this
  143. function is always safe to call. The default value is
  144. @c "www.yahoo.com:80".
  145. */
  146. virtual void SetWellKnownHost(const wxString& hostname,
  147. int portno = 80) = 0;
  148. };
  149. /**
  150. @class wxDialUpEvent
  151. This is the event class for the dialup events sent by wxDialUpManager.
  152. @library{wxcore}
  153. @category{events}
  154. */
  155. class wxDialUpEvent : public wxEvent
  156. {
  157. public:
  158. /**
  159. Constructor is only used by wxDialUpManager.
  160. */
  161. wxDialUpEvent(bool isConnected, bool isOwnEvent);
  162. /**
  163. Is this a @c CONNECTED or @c DISCONNECTED event? In other words, does
  164. it notify about transition from offline to online state or vice versa?
  165. */
  166. bool IsConnectedEvent() const;
  167. /**
  168. Does this event come from wxDialUpManager::Dial() or from some external
  169. process (i.e. does it result from our own attempt to establish the
  170. connection)?
  171. */
  172. bool IsOwnEvent() const;
  173. };