1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Network related wxWindows classes and functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dialup.h"
19 #if wxUSE_DIALUP_MANAGER
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 class WXDLLEXPORT wxArrayString
;
27 extern const wxChar
*wxEmptyString
;
29 #define WXDIALUP_MANAGER_DEFAULT_BEACONHOST T("www.yahoo.com")
31 // ----------------------------------------------------------------------------
32 // A class which groups functions dealing with connecting to the network from a
33 // workstation using dial-up access to the net. There is at most one instance
34 // of this class in the program accessed via GetDialUpManager().
35 // ----------------------------------------------------------------------------
39 * 1. more configurability for Unix: i.e. how to initiate the connection, how
40 * to check for online status, &c.
41 * 2. a function to enumerate all connections (ISPs) and show a dialog in
42 * Dial() allowing to choose between them if no ISP given
43 * 3. add an async version of dialing functions which notify the caller about
44 * the progress (or may be even start another thread to monitor it)
45 * 4. the static creation/accessor functions are not MT-safe - but is this
46 * really crucial? I think we may suppose they're always called from the
50 class WXDLLEXPORT wxDialUpManager
53 // this function should create and return the object of the
54 // platform-specific class derived from wxDialUpManager. It's implemented
55 // in the platform-specific source files.
56 static wxDialUpManager
*Create();
58 // could the dialup manager be initialized correctly? If this function
59 // returns FALSE, no other functions will work neither, so it's a good idea
60 // to call this function and check its result before calling any other
61 // wxDialUpManager methods
62 virtual bool IsOk() const = 0;
64 // virtual dtor for any base class
65 virtual ~wxDialUpManager() { }
70 // fills the array with the names of all possible values for the first
71 // parameter to Dial() on this machine and returns their number (may be 0)
72 virtual size_t GetISPNames(wxArrayString
& names
) const = 0;
74 // dial the given ISP, use username and password to authentificate
76 // if no nameOfISP is given, the function will select the default one
78 // if no username/password are given, the function will try to do without
79 // them, but will ask the user if really needed
81 // if async parameter is FALSE, the function waits until the end of dialing
82 // and returns TRUE upon successful completion.
83 // if async is TRUE, the function only initiates the connection and returns
84 // immediately - the result is reported via events (an event is sent
85 // anyhow, but if dialing failed it will be a DISCONNECTED one)
86 virtual bool Dial(const wxString
& nameOfISP
= wxEmptyString
,
87 const wxString
& username
= wxEmptyString
,
88 const wxString
& password
= wxEmptyString
,
89 bool async
= TRUE
) = 0;
91 // returns TRUE if (async) dialing is in progress
92 virtual bool IsDialing() const = 0;
94 // cancel dialing the number initiated with Dial(async = TRUE)
95 // NB: this won't result in DISCONNECTED event being sent
96 virtual bool CancelDialing() = 0;
98 // hang up the currently active dial up connection
99 virtual bool HangUp() = 0;
104 // returns TRUE if the computer has a permanent network connection (i.e. is
105 // on a LAN) and so there is no need to use Dial() function to go online
107 // NB: this functions tries to guess the result and it is not always
108 // guaranteed to be correct, so it's better to ask user for
109 // confirmation or give him a possibility to override it
110 virtual bool IsAlwaysOnline() const = 0;
112 // returns TRUE if the computer is connected to the network: under Windows,
113 // this just means that a RAS connection exists, under Unix we check that
114 // the "well-known host" (as specified by SetWellKnownHost) is reachable
115 virtual bool IsOnline() const = 0;
117 // sometimes the built-in logic for determining the online status may fail,
118 // so, in general, the user should be allowed to override it. This function
119 // allows to forcefully set the online status - whatever our internal
120 // algorithm may think about it.
121 virtual void SetOnlineStatus(bool isOnline
= TRUE
) = 0;
123 // set misc wxDialUpManager options
124 // --------------------------------
126 // enable automatical checks for the connection status and sending of
127 // wxEVT_DIALUP_CONNECTED/wxEVT_DIALUP_DISCONNECTED events. The interval
128 // parameter is only for Unix where we do the check manually: under
129 // Windows, the notification about the change of connection status is
132 // Returns FALSE if couldn't set up automatic check for online status.
133 virtual bool EnableAutoCheckOnlineStatus(size_t nSeconds
= 60) = 0;
135 // disable automatic check for connection status change - notice that the
136 // wxEVT_DIALUP_XXX events won't be sent any more neither.
137 virtual void DisableAutoCheckOnlineStatus() = 0;
139 // additional Unix-only configuration
140 // ----------------------------------
142 // under Unix, the value of well-known host is used to check whether we're
143 // connected to the internet. It's unused under Windows, but this function
144 // is always safe to call. The default value is www.yahoo.com.
145 virtual void SetWellKnownHost(const wxString
& hostname
,
146 int portno
= 80) = 0;
148 // Sets the commands to start up the network and to hang up again. Used by
149 // the Unix implementations only.
151 SetConnectCommand(const wxString
& commandDial
= T("/usr/bin/pon"),
152 const wxString
& commandHangup
= T("/usr/bin/poff")) = 0;
155 // ----------------------------------------------------------------------------
156 // DIALUP events processing
157 // ----------------------------------------------------------------------------
159 // the event class for the dialup events
160 class WXDLLEXPORT wxDialUpEvent
: public wxEvent
163 wxDialUpEvent(bool isConnected
, bool isOwnEvent
) : wxEvent(isOwnEvent
)
165 SetEventType(isConnected
? wxEVT_DIALUP_CONNECTED
166 : wxEVT_DIALUP_DISCONNECTED
);
169 // is this a CONNECTED or DISCONNECTED event?
170 bool IsConnectedEvent() const
171 { return GetEventType() == wxEVT_DIALUP_CONNECTED
; }
173 // does this event come from wxDialUpManager::Dial() or from some extrenal
174 // process (i.e. does it result from our own attempt to establish the
176 bool IsOwnEvent() const { return m_id
!= 0; }
179 // the type of dialup event handler function
180 typedef void (wxObject::*wxDialUpEventFunction
)(wxDialUpEvent
&);
182 // macros to catch dialup events
183 #define EVT_DIALUP_CONNECTED(func) { wxEVT_DIALUP_CONNECTED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxDialUpEventFunction) & func, NULL},
184 #define EVT_DIALUP_DISCONNECTED(func) { wxEVT_DIALUP_DISCONNECTED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxDialUpEventFunction) & func, NULL},
186 #endif // wxUSE_DIALUP_MANAGER