diff --git a/src/servers/Jamfile b/src/servers/Jamfile index 607fdcf1dc..2b5a8578ed 100644 --- a/src/servers/Jamfile +++ b/src/servers/Jamfile @@ -5,8 +5,8 @@ SubInclude OBOS_TOP src servers input ; SubInclude OBOS_TOP src servers media ; SubInclude OBOS_TOP src servers media_addon ; SubInclude OBOS_TOP src servers midi ; +SubInclude OBOS_TOP src servers net ; SubInclude OBOS_TOP src servers print ; SubInclude OBOS_TOP src servers registrar ; SubInclude OBOS_TOP src servers screensaver ; SubInclude OBOS_TOP src servers syslog_daemon ; -# SubInclude OBOS_TOP src servers net ; diff --git a/src/servers/net/Jamfile b/src/servers/net/Jamfile index fe3180c129..c4b008a3f3 100644 --- a/src/servers/net/Jamfile +++ b/src/servers/net/Jamfile @@ -3,13 +3,20 @@ SubDir OBOS_TOP src servers net ; UsePrivateHeaders net ; Server net_server : - userland_server.c - userland_ipc.c + NetServer.cpp + + # utils + SimpleMessageFilter.cpp + + # built-in add-ons + PPPServer.cpp + + # old net_server (was a netstack tester app) +# userland_server.c +# userland_ipc.c ; LinkSharedOSLibs net_server : be - root - libnet.so + net ; - diff --git a/src/servers/net/NetServer.cpp b/src/servers/net/NetServer.cpp new file mode 100644 index 0000000000..a0af732787 --- /dev/null +++ b/src/servers/net/NetServer.cpp @@ -0,0 +1,77 @@ +//----------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de +//----------------------------------------------------------------------- + +#include +#include + + +static const char *kSignature = "application/x-obos.net_server"; + + +class NetServerApplication : public BApplication { + public: + NetServerApplication(); + + virtual void AboutRequested(); + virtual void ReadyToRun(); + // loads add-ons + virtual bool QuitRequested(); + // unloads add-ons +}; + + +int main() +{ + new NetServerApplication(); + + be_app->Run(); + + delete be_app; + + return 0; +} + + +NetServerApplication::NetServerApplication() + : BApplication(kSignature) +{ +} + + +void +NetServerApplication::AboutRequested() +{ + // the alert should not block because we might get _very_ important messages + (new BAlert("About...", + "OpenBeOS net_server\n\n" + "The net_server manages all userland tasks that " + "cannot be handled by the netstack.", + "Uhm...Cool?", NULL, NULL, B_WIDTH_AS_USUAL, + B_INFO_ALERT))->Go(NULL); +} + + +void +NetServerApplication::ReadyToRun() +{ + // load integrated add-ons + + + // TODO: load add-on binaries +} + + +bool +NetServerApplication::QuitRequested() +{ + // unload integrated add-ons + + + // TODO: unload add-on binaries + + return true; +} diff --git a/src/servers/net/PPPServer.cpp b/src/servers/net/PPPServer.cpp new file mode 100644 index 0000000000..7770fcc870 --- /dev/null +++ b/src/servers/net/PPPServer.cpp @@ -0,0 +1,48 @@ +//----------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de +//----------------------------------------------------------------------- + +#include "PPPServer.h" +#include "SimpleMessageFilter.h" +#include + + +// the message constants that should be filtered +static const uint32 *kPPPWhatValues = { + // PPPS_CONNECT, + 0 // end-of-list +}; + + +PPPServer::PPPServer() + : BHandler("PPPServer") +{ + be_app->AddHandler(this); + fFilter = new SimpleMessageFilter(kPPPWhatValues, this); + be_app->AddCommonFilter(fFilter); +} + + +PPPServer::~PPPServer() +{ + be_app->RemoveHandler(this); + be_app->RemoveCommonFilter(fFilter); + delete fFilter; +} + + +void +PPPServer::MessageReceived(BMessage *message) +{ + switch(message->what) { + // TODO: handle PPP stack messages + + // TODO: handle requests from DialUpPreflet + + default: + BHandler::MessageReceived(message); + } +} diff --git a/src/servers/net/PPPServer.h b/src/servers/net/PPPServer.h new file mode 100644 index 0000000000..ff11d76a75 --- /dev/null +++ b/src/servers/net/PPPServer.h @@ -0,0 +1,29 @@ +//----------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de +//----------------------------------------------------------------------- + +#ifndef _PPP_SERVER__H +#define _PPP_SERVER__H + +#include + +class SimpleMessageFilter; + + +class PPPServer : public BHandler { + public: + PPPServer(); + virtual ~PPPServer(); + + virtual void MessageReceived(BMessage *message); + // the SimpleMessageFilter routes ppp_server messages to this handler + + private: + SimpleMessageFilter *fFilter; +}; + + +#endif diff --git a/src/servers/net/SimpleMessageFilter.cpp b/src/servers/net/SimpleMessageFilter.cpp new file mode 100644 index 0000000000..13c76bf49d --- /dev/null +++ b/src/servers/net/SimpleMessageFilter.cpp @@ -0,0 +1,65 @@ +//----------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de +//----------------------------------------------------------------------- + +/*! \class SimpleMessageFilter + \brief This is a BMessageFilter that can filter multiple \a what values. + + This class extends the BMessageFilter's ability of handling one \a what value + to handling multiple \a what values. +*/ + +#include "SimpleMessageFilter.h" +#include + + +/*! \brief Creates a copy of the \a what array. + + \param what A pointer to an array of \a what values that should be filtered. + The end-of-list indicator is an element valued 0 (zero). + \param target The target for messages matching one of the \a what values. + If \a target == NULL the messages will be discarded. +*/ +SimpleMessageFilter::SimpleMessageFilter(const uint32 *what, BHandler *target) + : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE), + fTarget(target) +{ + if(!what) { + fWhatArray = NULL; + return; + } + + // include the trailing zero in the copy + int32 count = 0; + while(what[count++] != 0) + ; + fWhatArray = new uint32[count]; + memcpy(fWhatArray, what, count * sizeof(uint32)); +} + + +//! Frees the copied \a what array. +SimpleMessageFilter::~SimpleMessageFilter() +{ + delete fWhatArray; +} + + +//! Filters all messages that match the \a what array given in the constructor. +filter_result +SimpleMessageFilter::Filter(BMessage *message, BHandler **target) +{ + for(int32 index = 0; fWhatArray[index] != 0; index++) + if(fWhatArray[index] == message->what) { + if(!fTarget) + return B_SKIP_MESSAGE; + + *target = fTarget; + break; + } + + return B_DISPATCH_MESSAGE; +} diff --git a/src/servers/net/SimpleMessageFilter.h b/src/servers/net/SimpleMessageFilter.h new file mode 100644 index 0000000000..428907a5cd --- /dev/null +++ b/src/servers/net/SimpleMessageFilter.h @@ -0,0 +1,27 @@ +//----------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de +//----------------------------------------------------------------------- + +#ifndef _SIMPLE_MESSAGE_FILTER__H +#define _SIMPLE_MESSAGE_FILTER__H + +#include + + +class SimpleMessageFilter : public BMessageFilter { + public: + SimpleMessageFilter(const uint32 *what, BHandler *target); + virtual ~SimpleMessageFilter(); + + virtual filter_result Filter(BMessage *message, BHandler **target); + + private: + uint32 *fWhatArray; + BHandler *fTarget; +}; + + +#endif