Work in progress. Untested.
All ppp_up instances are now maintained by KPPPManager. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10113 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b1318016f9
commit
9c15eafc5d
@ -1,76 +1,134 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "ConnectionView.h"
|
||||
#include <MessageDriverSettingsUtils.h>
|
||||
|
||||
#include <Application.h>
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <PPPInterface.h>
|
||||
#include <PPPManager.h>
|
||||
#include <settings_tools.h>
|
||||
#include <stl_algobase.h>
|
||||
// for max()
|
||||
|
||||
|
||||
static const char *kLabelConnect = "Connect";
|
||||
static const char *kLabelCancel = "Cancel";
|
||||
// GUI constants
|
||||
static const uint32 kDefaultButtonWidth = 80;
|
||||
|
||||
// message constants
|
||||
static const uint32 kMsgCancel = 'CANC';
|
||||
static const uint32 kMsgConnect = 'CONN';
|
||||
|
||||
static const uint32 kDefaultButtonWidth = 80;
|
||||
// labels
|
||||
static const char *kLabelSavePassword = "Save Password";
|
||||
static const char *kLabelName = "Username: ";
|
||||
static const char *kLabelPassword = "Password: ";
|
||||
static const char *kLabelConnect = "Connect";
|
||||
static const char *kLabelCancel = "Cancel";
|
||||
|
||||
// connection status strings
|
||||
static const char *kTextConnecting = "Connecting...";
|
||||
static const char *kTextConnectionEstablished = "Connection established.";
|
||||
static const char *kTextNotConnected = "Not connected.";
|
||||
static const char *kTextDeviceUpFailed = "Failed to connect.";
|
||||
static const char *kTextAuthenticating = "Authenticating...";
|
||||
static const char *kTextAuthenticationFailed = "Authentication failed!";
|
||||
static const char *kTextConnectionLost = "Connection lost!";
|
||||
|
||||
|
||||
ConnectionView::ConnectionView(BRect rect, ppp_interface_id id, thread_id thread,
|
||||
DialUpView *dun)
|
||||
static
|
||||
status_t
|
||||
up_thread(void *data)
|
||||
{
|
||||
PPPInterface *interface = static_cast<PPPInterface*>(data);
|
||||
interface->Up();
|
||||
delete interface;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
status_t
|
||||
down_thread(void *data)
|
||||
{
|
||||
PPPInterface *interface = static_cast<PPPInterface*>(data);
|
||||
interface->Down();
|
||||
delete interface;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
ConnectionView::ConnectionView(BRect rect, const char *name, ppp_interface_id id,
|
||||
thread_id thread)
|
||||
: BView(rect, "ConnectionView", B_FOLLOW_NONE, 0),
|
||||
fInterfaceName(name),
|
||||
fID(id),
|
||||
fRequestThread(thread),
|
||||
fDUNView(dun),
|
||||
fConnecting(false)
|
||||
fReportThread(thread),
|
||||
fConnecting(false),
|
||||
fKeepLabel(false),
|
||||
fReplyRequested(true)
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
BRect rect = Bounds();
|
||||
rect.InsetBy(5, 5);
|
||||
fAuthenticationView = dun->AuthenticationView();
|
||||
fAuthenticationView->RemoveSelf();
|
||||
fAuthenticationView->MoveTo(5, 5);
|
||||
AddChild(fAuthenticationView);
|
||||
rect.bottom = rect.top
|
||||
+ 25 // space for topmost control
|
||||
+ 3 * 20 // size of controls
|
||||
+ 3 * 5; // space beween controls and bottom of box
|
||||
BBox *authenticationBox = new BBox(rect, "Authentication");
|
||||
rect = authenticationBox->Bounds();
|
||||
rect.InsetBy(10, 5);
|
||||
rect.top = 25;
|
||||
BView *authenticationView = new BView(rect, "authenticationView",
|
||||
B_FOLLOW_NONE, 0);
|
||||
authenticationView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
rect = authenticationView->Bounds();
|
||||
rect.bottom = rect.top + 20;
|
||||
fUsername = new BTextControl(rect, "username", kLabelName, NULL, NULL);
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 20;
|
||||
fPassword = new BTextControl(rect, "password", kLabelPassword, NULL, NULL);
|
||||
fPassword->TextView()->HideTyping(true);
|
||||
|
||||
rect.top = fAuthenticationView->Frame().bottom + 15;
|
||||
// set dividers
|
||||
float width = max(StringWidth(fUsername->Label()),
|
||||
StringWidth(fPassword->Label()));
|
||||
fUsername->SetDivider(width + 5);
|
||||
fPassword->SetDivider(width + 5);
|
||||
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 20;
|
||||
fSavePassword = new BCheckBox(rect, "SavePassword", kLabelSavePassword, NULL);
|
||||
|
||||
authenticationView->AddChild(fUsername);
|
||||
authenticationView->AddChild(fPassword);
|
||||
authenticationView->AddChild(fSavePassword);
|
||||
authenticationBox->AddChild(authenticationView);
|
||||
AddChild(authenticationBox);
|
||||
|
||||
rect = authenticationBox->Frame();
|
||||
rect.top = rect.bottom + 10;
|
||||
rect.bottom = rect.top + 15;
|
||||
fAttemptView = new BStringView(rect, "AttemptView", AttemptString().String());
|
||||
AddChild(fAttemptView);
|
||||
|
||||
// add status view
|
||||
rect.top = rect.bottom + 5;
|
||||
fStatusView = dun->StatusView();
|
||||
fStatusView->RemoveSelf();
|
||||
fStatusView->MoveTo(5, rect.top);
|
||||
rect.bottom = rect.top + 15;
|
||||
fStatusView = new BStringView(rect, "StatusView", "");
|
||||
AddChild(fStatusView);
|
||||
|
||||
rect.top = fStatusView->Frame().bottom + 10;
|
||||
// add "Connect" and "Cancel" buttons
|
||||
rect.top = rect.bottom + 10;
|
||||
rect.bottom = rect.top + 25;
|
||||
rect.right = rect.left + kDefaultButtonWidth;
|
||||
fConnectButton = new BButton(rect, "ConnectButton", kLabelConnect,
|
||||
@ -84,6 +142,13 @@ ConnectionView::ConnectionView(BRect rect, ppp_interface_id id, thread_id thread
|
||||
|
||||
AddChild(fConnectButton);
|
||||
AddChild(fCancelButton);
|
||||
|
||||
// initialize PTPSettings
|
||||
fSettings.LoadAddons(false);
|
||||
// add PPPUpAddon
|
||||
fAddon = new PPPUpAddon(&fSettings.Addons(), this);
|
||||
fSettings.Addons().AddPointer(DUN_TAB_ADDON_TYPE, fAddon);
|
||||
fSettings.Addons().AddPointer(DUN_DELETE_ON_QUIT, fAddon);
|
||||
}
|
||||
|
||||
|
||||
@ -92,8 +157,10 @@ ConnectionView::AttachedToWindow()
|
||||
{
|
||||
fConnectButton->SetTarget(this);
|
||||
fCancelButton->SetTarget(this);
|
||||
fSettings.LoadSettings(fInterfaceName.String(), false);
|
||||
|
||||
if(fDUNView->NeedsRequest() == false)
|
||||
if(fAddon->CountAuthenticators() == 0 || fAddon->HasPassword())
|
||||
// TODO: || AskBeforeDialing == true
|
||||
Connect();
|
||||
}
|
||||
|
||||
@ -102,12 +169,15 @@ void
|
||||
ConnectionView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case MSG_UPDATE:
|
||||
Update();
|
||||
break;
|
||||
case MSG_UPDATE: {
|
||||
UpdateStatus(message->FindInt32("code"));
|
||||
ppp_interface_id id;
|
||||
if(message->FindInt32("interface", reinterpret_cast<int32*>(&id)) == B_OK)
|
||||
fID = id;
|
||||
} break;
|
||||
|
||||
case MSG_UP_FAILED:
|
||||
UpFailed();
|
||||
case MSG_REPLY:
|
||||
message->SendReply(B_OK);
|
||||
break;
|
||||
|
||||
case kMsgConnect:
|
||||
@ -124,55 +194,73 @@ ConnectionView::MessageReceived(BMessage *message)
|
||||
}
|
||||
|
||||
|
||||
// update authentication UI
|
||||
void
|
||||
ConnectionView::Update()
|
||||
ConnectionView::Reload()
|
||||
{
|
||||
fAttemptView->SetText(AttemptString().String());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConnectionView::UpFailed()
|
||||
{
|
||||
Update();
|
||||
fConnectButton->SetEnabled(true);
|
||||
fUsername->SetText(Addon()->Username());
|
||||
fPassword->SetText(Addon()->Password());
|
||||
fSavePassword->SetValue(Addon()->HasPassword());
|
||||
|
||||
if(Addon()->CountAuthenticators() > 0) {
|
||||
fUsername->SetEnabled(true);
|
||||
fPassword->SetEnabled(true);
|
||||
fSavePassword->SetEnabled(true);
|
||||
} else {
|
||||
fUsername->SetEnabled(false);
|
||||
fPassword->SetEnabled(false);
|
||||
fSavePassword->SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConnectionView::Connect()
|
||||
{
|
||||
fSettings.SaveSettingsToFile();
|
||||
|
||||
// update interface profile
|
||||
BMessage settings, profile;
|
||||
fDUNView->SaveSettings(&settings, &profile, true);
|
||||
fSettings.SaveSettings(&settings, &profile, true);
|
||||
driver_settings *temporaryProfile = MessageToDriverSettings(profile);
|
||||
PPPInterface interface(fID);
|
||||
interface.SetProfile(temporaryProfile);
|
||||
PPPInterface *interface = new PPPInterface(PPPManager().CreateInterfaceWithName(
|
||||
fInterfaceName.String()));
|
||||
interface->SetProfile(temporaryProfile);
|
||||
free_driver_settings(temporaryProfile);
|
||||
|
||||
fConnectButton->SetEnabled(false);
|
||||
fConnecting = true;
|
||||
|
||||
send_data(fRequestThread, B_OK, NULL, 0);
|
||||
if(fReplyRequested) {
|
||||
fReplyRequested = false;
|
||||
send_data(fReportThread, B_OK, NULL, 0);
|
||||
delete interface;
|
||||
} else {
|
||||
thread_id up = spawn_thread(up_thread, "up_thread", B_NORMAL_PRIORITY,
|
||||
interface);
|
||||
resume_thread(up);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConnectionView::Cancel()
|
||||
{
|
||||
if(fConnecting) {
|
||||
// only disconnect if we are not connected yet
|
||||
PPPInterface interface(fID);
|
||||
if(fReplyRequested) {
|
||||
fReplyRequested = false;
|
||||
send_data(fReportThread, B_ERROR, NULL, 0);
|
||||
// tell requestor to cancel connection attempt
|
||||
} else {
|
||||
PPPInterface *interface = new PPPInterface(fID);
|
||||
ppp_interface_info_t info;
|
||||
interface.GetInterfaceInfo(&info);
|
||||
interface->GetInterfaceInfo(&info);
|
||||
|
||||
if(info.info.phase < PPP_ESTABLISHED_PHASE) {
|
||||
interface.Down();
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
} else {
|
||||
send_data(fRequestThread, B_ERROR, NULL, 0);
|
||||
// tell requestor to cancel connection attempt
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
thread_id down = spawn_thread(down_thread, "up_thread", B_NORMAL_PRIORITY,
|
||||
interface);
|
||||
resume_thread(down);
|
||||
} else
|
||||
delete interface;
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,11 +269,9 @@ ConnectionView::Cancel()
|
||||
void
|
||||
ConnectionView::CleanUp()
|
||||
{
|
||||
// give the "stolen" views back to make sure they are not deleted too early
|
||||
fAuthenticationView->RemoveSelf();
|
||||
fDUNView->AddChild(fAuthenticationView);
|
||||
fStatusView->RemoveSelf();
|
||||
fDUNView->AddChild(fStatusView);
|
||||
// TODO: finish clean-up; (DONE?)
|
||||
if(fReplyRequested)
|
||||
Cancel();
|
||||
}
|
||||
|
||||
|
||||
@ -201,3 +287,68 @@ ConnectionView::AttemptString() const
|
||||
|
||||
return attempt;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConnectionView::UpdateStatus(int32 code)
|
||||
{
|
||||
fAttemptView->SetText(AttemptString().String());
|
||||
|
||||
switch(code) {
|
||||
case PPP_REPORT_UP_ABORTED:
|
||||
case PPP_REPORT_DEVICE_UP_FAILED:
|
||||
case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED:
|
||||
case PPP_REPORT_PEER_AUTHENTICATION_FAILED:
|
||||
case PPP_REPORT_DOWN_SUCCESSFUL:
|
||||
case PPP_REPORT_CONNECTION_LOST:
|
||||
fConnectButton->SetEnabled(true);
|
||||
break;
|
||||
|
||||
default:
|
||||
fConnectButton->SetEnabled(false);
|
||||
}
|
||||
|
||||
// maybe the status string must not be changed (codes that set fKeepLabel to false
|
||||
// should still be handled)
|
||||
if(fKeepLabel && code != PPP_REPORT_GOING_UP && code != PPP_REPORT_UP_SUCCESSFUL)
|
||||
return;
|
||||
|
||||
// only errors should set fKeepLabel to true
|
||||
switch(code) {
|
||||
case PPP_REPORT_GOING_UP:
|
||||
fKeepLabel = false;
|
||||
fStatusView->SetText(kTextConnecting);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_UP_SUCCESSFUL:
|
||||
fKeepLabel = false;
|
||||
fStatusView->SetText(kTextConnectionEstablished);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_UP_ABORTED:
|
||||
case PPP_REPORT_DOWN_SUCCESSFUL:
|
||||
fStatusView->SetText(kTextNotConnected);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_DEVICE_UP_FAILED:
|
||||
fKeepLabel = true;
|
||||
fStatusView->SetText(kTextDeviceUpFailed);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_LOCAL_AUTHENTICATION_REQUESTED:
|
||||
case PPP_REPORT_PEER_AUTHENTICATION_REQUESTED:
|
||||
fStatusView->SetText(kTextAuthenticating);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED:
|
||||
case PPP_REPORT_PEER_AUTHENTICATION_FAILED:
|
||||
fKeepLabel = true;
|
||||
fStatusView->SetText(kTextAuthenticationFailed);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_CONNECTION_LOST:
|
||||
fKeepLabel = true;
|
||||
fStatusView->SetText(kTextConnectionLost);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +1,68 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef CONNECTION_VIEW__H
|
||||
#define CONNECTION_VIEW__H
|
||||
|
||||
#include "DialUpView.h"
|
||||
#include <View.h>
|
||||
#include <PPPDefs.h>
|
||||
#include "PPPUpAddon.h"
|
||||
#include <PTPSettings.h>
|
||||
|
||||
|
||||
#define MSG_UPDATE 'UPDT'
|
||||
// sent when status changed
|
||||
#define MSG_UP_FAILED 'UPFL'
|
||||
// sent when up failed
|
||||
#define MSG_UPDATE 'MUPD'
|
||||
#define MSG_REPLY 'MRPY'
|
||||
|
||||
|
||||
class ConnectionView : public BView {
|
||||
friend class ConnectionWindow;
|
||||
|
||||
public:
|
||||
ConnectionView(BRect rect, ppp_interface_id id, thread_id thread,
|
||||
DialUpView *view);
|
||||
ConnectionView(BRect rect, const char *name, ppp_interface_id id,
|
||||
thread_id thread);
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
// for PPPUpAddon
|
||||
PPPUpAddon *Addon() const
|
||||
{ return fAddon; }
|
||||
void Reload();
|
||||
const char *Username() const
|
||||
{ return fUsername->Text(); }
|
||||
const char *Password() const
|
||||
{ return fPassword->Text(); }
|
||||
bool DoesSavePassword() const
|
||||
{ return fSavePassword->Value(); }
|
||||
|
||||
bool HasTemporaryProfile() const
|
||||
{ return !DoesSavePassword(); }
|
||||
void IsDeviceModified(bool *settings, bool *profile) const
|
||||
{ if(settings) *settings = false; if(profile) *profile = false; }
|
||||
|
||||
private:
|
||||
void Update();
|
||||
void UpFailed();
|
||||
void Connect();
|
||||
void Cancel();
|
||||
void CleanUp();
|
||||
|
||||
BString AttemptString() const;
|
||||
void UpdateStatus(int32 code);
|
||||
|
||||
private:
|
||||
PPPUpAddon *fAddon;
|
||||
BString fInterfaceName;
|
||||
ppp_interface_id fID;
|
||||
thread_id fRequestThread;
|
||||
BView *fAuthenticationView, *fStatusView;
|
||||
DialUpView *fDUNView;
|
||||
BStringView *fAttemptView;
|
||||
thread_id fReportThread;
|
||||
|
||||
BTextControl *fUsername, *fPassword;
|
||||
BCheckBox *fSavePassword;
|
||||
BStringView *fAttemptView, *fStatusView;
|
||||
BButton *fConnectButton, *fCancelButton;
|
||||
bool fConnecting;
|
||||
|
||||
bool fConnecting, fKeepLabel, fReplyRequested;
|
||||
PTPSettings fSettings;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,39 +1,23 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "ConnectionWindow.h"
|
||||
|
||||
#include <Application.h>
|
||||
#include <String.h>
|
||||
|
||||
ConnectionWindow::ConnectionWindow(BRect frame, ppp_interface_id id,
|
||||
|
||||
ConnectionWindow::ConnectionWindow(BRect frame, const char *name, ppp_interface_id id,
|
||||
thread_id replyThread)
|
||||
: BWindow(frame, "Connecting...", B_MODAL_WINDOW,
|
||||
: BWindow(frame, "", B_MODAL_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
||||
{
|
||||
BRect bounds = Bounds();
|
||||
bounds.OffsetBy(bounds.Width() + 5, 0);
|
||||
DialUpView *dun = new DialUpView(bounds);
|
||||
fConnectionView = new ConnectionView(Bounds(), id, replyThread, dun);
|
||||
|
||||
AddChild(dun);
|
||||
BString title("Connecting to ");
|
||||
title << "\"" << name << "\"...";
|
||||
SetTitle(title.String());
|
||||
fConnectionView = new ConnectionView(Bounds(), name, id, replyThread);
|
||||
AddChild(fConnectionView);
|
||||
}
|
||||
|
||||
@ -43,5 +27,25 @@ ConnectionWindow::QuitRequested()
|
||||
{
|
||||
fConnectionView->CleanUp();
|
||||
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConnectionWindow::UpdateStatus(BMessage& message)
|
||||
{
|
||||
message.what = MSG_UPDATE;
|
||||
PostMessage(&message, fConnectionView);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ConnectionWindow::ResponseTest()
|
||||
{
|
||||
// test if we dead-locked
|
||||
Lock();
|
||||
Unlock();
|
||||
return true;
|
||||
}
|
||||
|
@ -1,24 +1,7 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef CONNECTION_WINDOW__H
|
||||
#define CONNECTION_WINDOW__H
|
||||
@ -29,9 +12,14 @@
|
||||
|
||||
class ConnectionWindow : public BWindow {
|
||||
public:
|
||||
ConnectionWindow(BRect frame, ppp_interface_id id, thread_id replyThread);
|
||||
ConnectionWindow(BRect frame, const char *name, ppp_interface_id id,
|
||||
thread_id replyThread);
|
||||
|
||||
virtual bool QuitRequested();
|
||||
void RequestReply()
|
||||
{ fConnectionView->fReplyRequested = true; }
|
||||
void UpdateStatus(BMessage& message);
|
||||
bool ResponseTest();
|
||||
|
||||
private:
|
||||
ConnectionView *fConnectionView;
|
||||
|
@ -10,7 +10,17 @@ AddResources ppp_up : ppp_up.rdef ;
|
||||
BinCommand ppp_up :
|
||||
ConnectionView.cpp
|
||||
ConnectionWindow.cpp
|
||||
PPPUpAddon.cpp
|
||||
PPPUpApplication.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs ppp_up : libdunview.a libppp.a be ;
|
||||
LinkSharedOSLibs ppp_up : libptpnet.a libppp.a be ;
|
||||
|
||||
# Installation
|
||||
OBOSInstall install-networking
|
||||
: /boot/beos/bin
|
||||
: ppp_up ;
|
||||
|
||||
Package haiku-networkingkit-cvs :
|
||||
ppp_up :
|
||||
boot beos bin ;
|
||||
|
@ -1,24 +1,7 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "PPPDeskbarReplicant.h"
|
||||
#include "ConnectionWindow.h"
|
||||
|
@ -1,24 +1,7 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef PPP_DESKBAR_REPLICANT__H
|
||||
#define PPP_DESKBAR_REPLICANT__H
|
||||
|
@ -1,30 +1,15 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "DialUpView.h"
|
||||
#include "ConnectionWindow.h"
|
||||
#include <KPPPUtils.h>
|
||||
#include <PPPReportDefs.h>
|
||||
|
||||
|
||||
static const char *kSignature = "application/x-vnd.haiku.ppp_up";
|
||||
@ -32,6 +17,28 @@ static const char *kSignature = "application/x-vnd.haiku.ppp_up";
|
||||
extern "C" _EXPORT BView *instantiate_deskbar_item();
|
||||
|
||||
|
||||
class PPPUpApplication : public BApplication {
|
||||
public:
|
||||
PPPUpApplication(const char *name, ppp_interface_id id,
|
||||
thread_id replyThread);
|
||||
|
||||
virtual void ReadyToRun();
|
||||
|
||||
const char *Name() const
|
||||
{ return fName; }
|
||||
ppp_interface_id ID() const
|
||||
{ return fID; }
|
||||
thread_id ReplyThread() const
|
||||
{ return fReplyThread; }
|
||||
|
||||
private:
|
||||
const char *fName;
|
||||
ppp_interface_id fID;
|
||||
thread_id fReplyThread;
|
||||
ConnectionWindow *fWindow;
|
||||
};
|
||||
|
||||
|
||||
BView*
|
||||
instantiate_deskbar_item()
|
||||
{
|
||||
@ -44,29 +51,79 @@ static
|
||||
status_t
|
||||
report_thread(void *data)
|
||||
{
|
||||
// TODO: add replicant when we finished connecting
|
||||
PPPUpApplication *app = static_cast<PPPUpApplication*>(data);
|
||||
|
||||
// Send reply. From now on we will receive report messages.
|
||||
send_data(app->ReplyThread(), 0, NULL, 0);
|
||||
|
||||
// get messages and open connection window when we receive a GOING_UP report
|
||||
thread_id sender, me = find_thread(NULL);
|
||||
int32 reportCode;
|
||||
ppp_interface_id id;
|
||||
ppp_report_packet report;
|
||||
ConnectionWindow *window = NULL;
|
||||
while(true) {
|
||||
reportCode = receive_data(&sender, &report, sizeof(report));
|
||||
if(reportCode == PPP_RESPONSE_TEST_CODE) {
|
||||
if(!window || window->ResponseTest())
|
||||
PPP_REPLY(sender, B_OK);
|
||||
else
|
||||
PPP_REPLY(sender, B_ERROR);
|
||||
continue;
|
||||
} else if(reportCode != PPP_REPORT_CODE)
|
||||
continue;
|
||||
|
||||
if(report.type == PPP_DESTRUCTION_REPORT) {
|
||||
id = PPP_UNDEFINED_INTERFACE_ID;
|
||||
PPP_REPLY(sender, B_OK);
|
||||
} else if(report.type != PPP_CONNECTION_REPORT) {
|
||||
PPP_REPLY(sender, B_OK);
|
||||
continue;
|
||||
} else if(report.length == sizeof(ppp_interface_id))
|
||||
memcpy(&id, report.data, sizeof(ppp_interface_id));
|
||||
else
|
||||
id = PPP_UNDEFINED_INTERFACE_ID;
|
||||
|
||||
// notify window
|
||||
if(window && (report.type == PPP_DESTRUCTION_REPORT
|
||||
|| report.type == PPP_CONNECTION_REPORT)) {
|
||||
BMessage message;
|
||||
message.AddInt32("code", report.type == PPP_DESTRUCTION_REPORT
|
||||
? PPP_REPORT_DOWN_SUCCESSFUL : report.code);
|
||||
message.AddInt32("interface", id);
|
||||
window->UpdateStatus(message);
|
||||
}
|
||||
|
||||
if(report.code == PPP_REPORT_GOING_UP) {
|
||||
// TODO:
|
||||
// create connection window (it will send the reply for us) (DONE?)
|
||||
BRect rect(150, 50, 450, 435);
|
||||
if(!window) {
|
||||
window = new ConnectionWindow(rect, app->Name(), app->ID(), me);
|
||||
window->Show();
|
||||
}
|
||||
|
||||
window->RequestReply();
|
||||
// wait for reply from window and forward it to the kernel
|
||||
thread_id tmp;
|
||||
PPP_REPLY(sender, receive_data(&tmp, NULL, 0));
|
||||
|
||||
// PPP_REPLY(sender, B_OK);
|
||||
// TODO: remove this when finished with above
|
||||
} else {
|
||||
if(report.code == PPP_REPORT_UP_SUCCESSFUL)
|
||||
; // TODO: add deskbar replicant
|
||||
|
||||
PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS);
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
class PPPUpApplication : public BApplication {
|
||||
public:
|
||||
PPPUpApplication(const char *name, ppp_interface_id id,
|
||||
thread_id replyThread);
|
||||
|
||||
virtual void ReadyToRun();
|
||||
|
||||
private:
|
||||
const char *fName;
|
||||
ppp_interface_id fID;
|
||||
thread_id fReplyThread;
|
||||
ConnectionWindow *fWindow;
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
main(const char *argv[], int argc)
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
if(argc != 2)
|
||||
return -1;
|
||||
@ -78,9 +135,7 @@ main(const char *argv[], int argc)
|
||||
receive_data(&replyThread, &id, sizeof(id));
|
||||
|
||||
new PPPUpApplication(name, id, replyThread);
|
||||
|
||||
be_app->Run();
|
||||
|
||||
delete be_app;
|
||||
|
||||
return 0;
|
||||
@ -92,8 +147,7 @@ PPPUpApplication::PPPUpApplication(const char *name, ppp_interface_id id,
|
||||
: BApplication(kSignature),
|
||||
fName(name),
|
||||
fID(id),
|
||||
fReplyThread(replyThread),
|
||||
fWindow(NULL)
|
||||
fReplyThread(replyThread)
|
||||
{
|
||||
}
|
||||
|
||||
@ -101,6 +155,9 @@ PPPUpApplication::PPPUpApplication(const char *name, ppp_interface_id id,
|
||||
void
|
||||
PPPUpApplication::ReadyToRun()
|
||||
{
|
||||
// TODO: create report message thread (which in turn sends the reply)
|
||||
// TODO: create connection window
|
||||
// Create report message thread (which in turn sends the reply and creates
|
||||
// the connection window). (DONE?)
|
||||
thread_id reportThread = spawn_thread(report_thread, "ppp_up: report_thread",
|
||||
B_NORMAL_PRIORITY, this);
|
||||
resume_thread(reportThread);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
If has temporary profile:
|
||||
Open connection window and request password.
|
||||
|
||||
Add Deskbar replicant.
|
||||
|
||||
I hope it is not too annoying that the user cannot select an alternative interface for connecting. The problem lies in the stack's concept that everything is an add-on. We cannot know if the connection-initiating packet type is supported by the alternative interface (or, we could, but we would have to load (and write) many add-ons that understand how the stack modules work).
|
||||
This problem is minimised by showing the device view which allows changing the phone number for modems, for example.
|
||||
|
||||
What if preflet changes profile while connecting?
|
||||
Add some indicator to the add-ons message that says we are ppp_up, not the preflet.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
pppinit.rdef
|
||||
ppp_up.rdef
|
||||
*/
|
||||
|
||||
resource app_signature "application/x-vnd.haiku.ppp_up";
|
||||
|
@ -1,24 +1,7 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright 2003-2004, Waldemar Kornewald <Waldemar.Kornewald@web.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <String.h>
|
||||
|
Loading…
Reference in New Issue
Block a user