1dceee0deSWaldemar Kornewald/*
26e17c55aSWaldemar Kornewald * Copyright 2004-2005, Waldemar Kornewald <wkornew@gmx.net>
3dceee0deSWaldemar Kornewald * Distributed under the terms of the MIT License.
4dceee0deSWaldemar Kornewald */
560abfca0SWaldemar Kornewald
660abfca0SWaldemar Kornewald#include "PPPServer.h"
760abfca0SWaldemar Kornewald#include <Application.h>
860abfca0SWaldemar Kornewald
960abfca0SWaldemar Kornewald
1060abfca0SWaldemar KornewaldPPPServer::PPPServer()
11abdb7d1aSWaldemar Kornewald	: BHandler("PPPServer"),
12abdb7d1aSWaldemar Kornewald	fListener(this)
1360abfca0SWaldemar Kornewald{
1460abfca0SWaldemar Kornewald	be_app->AddHandler(this);
152d73fabaSJérôme Duval
16abdb7d1aSWaldemar Kornewald	fListener.WatchManager();
172d73fabaSJérôme Duval
180a628cf2SWaldemar Kornewald	InitInterfaces();
1960abfca0SWaldemar Kornewald}
2060abfca0SWaldemar Kornewald
2160abfca0SWaldemar Kornewald
2260abfca0SWaldemar KornewaldPPPServer::~PPPServer()
2360abfca0SWaldemar Kornewald{
24abdb7d1aSWaldemar Kornewald	UninitInterfaces();
252d73fabaSJérôme Duval
26abdb7d1aSWaldemar Kornewald	fListener.StopWatchingManager();
272d73fabaSJérôme Duval
280a628cf2SWaldemar Kornewald	be_app->RemoveHandler(this);
2960abfca0SWaldemar Kornewald}
3060abfca0SWaldemar Kornewald
3160abfca0SWaldemar Kornewald
3260abfca0SWaldemar Kornewaldvoid
3360abfca0SWaldemar KornewaldPPPServer::MessageReceived(BMessage *message)
3460abfca0SWaldemar Kornewald{
3560abfca0SWaldemar Kornewald	switch(message->what) {
360a628cf2SWaldemar Kornewald		case PPP_REPORT_MESSAGE:
370a628cf2SWaldemar Kornewald			HandleReportMessage(message);
380a628cf2SWaldemar Kornewald		break;
392d73fabaSJérôme Duval
4060abfca0SWaldemar Kornewald		default:
4160abfca0SWaldemar Kornewald			BHandler::MessageReceived(message);
4260abfca0SWaldemar Kornewald	}
4360abfca0SWaldemar Kornewald}
440a628cf2SWaldemar Kornewald
450a628cf2SWaldemar Kornewald
460a628cf2SWaldemar Kornewaldvoid
470a628cf2SWaldemar KornewaldPPPServer::InitInterfaces()
480a628cf2SWaldemar Kornewald{
49abdb7d1aSWaldemar Kornewald	// TODO: create one ConnectionRequestWindow per interface
500a628cf2SWaldemar Kornewald}
510a628cf2SWaldemar Kornewald
520a628cf2SWaldemar Kornewald
53abdb7d1aSWaldemar Kornewaldvoid
54abdb7d1aSWaldemar KornewaldPPPServer::UninitInterfaces()
550a628cf2SWaldemar Kornewald{
56abdb7d1aSWaldemar Kornewald	// TODO: delete all ConnectionRequestWindows
570a628cf2SWaldemar Kornewald}
580a628cf2SWaldemar Kornewald
590a628cf2SWaldemar Kornewald
600a628cf2SWaldemar Kornewaldvoid
610a628cf2SWaldemar KornewaldPPPServer::HandleReportMessage(BMessage *message)
620a628cf2SWaldemar Kornewald{
630a628cf2SWaldemar Kornewald	ppp_interface_id id;
642d73fabaSJérôme Duval	if (message->FindInt32("interface", reinterpret_cast<int32*>(&id)) != B_OK)
650a628cf2SWaldemar Kornewald		return;
662d73fabaSJérôme Duval
670a628cf2SWaldemar Kornewald	int32 type, code;
680a628cf2SWaldemar Kornewald	message->FindInt32("type", &type);
690a628cf2SWaldemar Kornewald	message->FindInt32("code", &code);
702d73fabaSJérôme Duval
712d73fabaSJérôme Duval	if (type == PPP_MANAGER_REPORT && code == PPP_REPORT_INTERFACE_CREATED)
72abdb7d1aSWaldemar Kornewald		CreateConnectionRequestWindow(id);
730a628cf2SWaldemar Kornewald}
74dceee0deSWaldemar Kornewald
75dceee0deSWaldemar Kornewald
76dceee0deSWaldemar Kornewaldvoid
77abdb7d1aSWaldemar KornewaldPPPServer::CreateConnectionRequestWindow(ppp_interface_id id)
78dceee0deSWaldemar Kornewald{
79abdb7d1aSWaldemar Kornewald	// TODO: create window, register window as report receiver for the interface
80abdb7d1aSWaldemar Kornewald	// XXX: if a window for that ID exists then only register it as report receiver
81dceee0deSWaldemar Kornewald}
82