diff options
Diffstat (limited to 'networkstatus')
-rw-r--r-- | networkstatus/Makefile.am | 35 | ||||
-rw-r--r-- | networkstatus/README.statetransition | 29 | ||||
-rw-r--r-- | networkstatus/clientiface.h | 77 | ||||
-rw-r--r-- | networkstatus/clientifaceimpl.cpp | 51 | ||||
-rw-r--r-- | networkstatus/clientifaceimpl.h | 43 | ||||
-rw-r--r-- | networkstatus/connectionmanager.cpp | 156 | ||||
-rw-r--r-- | networkstatus/connectionmanager.h | 57 | ||||
-rw-r--r-- | networkstatus/network.cpp | 93 | ||||
-rw-r--r-- | networkstatus/network.h | 67 | ||||
-rw-r--r-- | networkstatus/networkstatus.cpp | 307 | ||||
-rw-r--r-- | networkstatus/networkstatus.desktop | 102 | ||||
-rw-r--r-- | networkstatus/networkstatus.h | 80 | ||||
-rw-r--r-- | networkstatus/networkstatus.kdevelop | 108 | ||||
-rw-r--r-- | networkstatus/networkstatuscommon.cpp | 53 | ||||
-rw-r--r-- | networkstatus/networkstatuscommon.h | 54 | ||||
-rw-r--r-- | networkstatus/provideriface.h | 42 | ||||
-rw-r--r-- | networkstatus/serviceiface.h | 51 | ||||
-rw-r--r-- | networkstatus/serviceifaceimpl.cpp | 46 | ||||
-rw-r--r-- | networkstatus/serviceifaceimpl.h | 43 | ||||
-rw-r--r-- | networkstatus/testservice.cpp | 101 | ||||
-rw-r--r-- | networkstatus/testservice.h | 49 |
21 files changed, 1644 insertions, 0 deletions
diff --git a/networkstatus/Makefile.am b/networkstatus/Makefile.am new file mode 100644 index 000000000..5b17f8dde --- /dev/null +++ b/networkstatus/Makefile.am @@ -0,0 +1,35 @@ +#SUBDIRS = networkstatustray + +METASOURCES = AUTO + +kde_module_LTLIBRARIES = kded_networkstatus.la +noinst_LTLIBRARIES = libnetworkstatus.la libconnectionmanager.la + +libnetworkstatus_la_LIBADD = $(LIB_KDECORE) +libnetworkstatus_la_LDFLAGS = $(all_libraries) +libnetworkstatus_la_SOURCES = networkstatuscommon.cpp + +libconnectionmanager_la_LIBADD = $(LIB_KDECORE) +libconnectionmanager_la_LDFLAGS = $(all_libraries) +libconnectionmanager_la_SOURCES = connectionmanager.cpp connectionmanager.skel clientiface.stub + +INCLUDES = $(all_includes) + +kded_networkstatus_la_SOURCES = networkstatus.cpp networkstatus.skel \ + clientiface.skel serviceiface.skel network.cpp +#kclientiface.skel serviceiface.skel +kded_networkstatus_la_LIBADD = $(LIB_KDECORE) $(LIB_KIO) ./libnetworkstatus.la +kded_networkstatus_la_LDFLAGS = $(all_libraries) -module -avoid-version + +servicesdir = $(kde_servicesdir)/kded +services_DATA = networkstatus.desktop + +noinst_HEADERS = serviceiface.h networkstatuscommon.h serviceifaceimpl.h \ + network.h clientifaceimpl.h provideriface.h testservice.h connectionmanager.h + +bin_PROGRAMS = networkstatustestservice + +networkstatustestservice_LDFLAGS = $(all_libraries) +networkstatustestservice_LDADD = libnetworkstatus.la + +networkstatustestservice_SOURCES = testservice.cpp provideriface.skel serviceiface.stub diff --git a/networkstatus/README.statetransition b/networkstatus/README.statetransition new file mode 100644 index 000000000..ac075ea77 --- /dev/null +++ b/networkstatus/README.statetransition @@ -0,0 +1,29 @@ +This table defines the actions to be taken on state transition. + +TODO: potentially add extra states OnlineReading and OnlineWriting + + NEW + |Offline | Online | +---+---+----------------+---------------+ + | | |N|set online | + | | |L|reload | + | O | |C|resources | + | F | +---------------+ + | F | |L|set online | +O | | |C|reload res. | +L | | | |write res. | +D +---+----------------+---------------+ + | |N|set offline | | + | |C| | | + | | | | | + | O +---------------+| | + | N |U|set offline | | + | |W|write locally | | + | |C|(subject to | | + | | | save policy)| | +---+---+----------------+---------------+ +LC = Local changes exist +NLC = No local changes exist +UWC = Unsaved changes exist +NC = no changes exist + diff --git a/networkstatus/clientiface.h b/networkstatus/clientiface.h new file mode 100644 index 000000000..d8caff6b2 --- /dev/null +++ b/networkstatus/clientiface.h @@ -0,0 +1,77 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDED_NETWORKSTATUS_CLIENTIFACE_H +#define KDED_NETWORKSTATUS_CLIENTIFACE_H + +#include "networkstatuscommon.h" + +#include <dcopobject.h> + +class ClientIface : virtual public DCOPObject +{ +K_DCOP +k_dcop: + /** Get the set of networks that the daemon is aware of. Mostly for debug */ + virtual QStringList networks() = 0; + /** + * Get the status of the connection to the given host. + * @param host + * @return a NetworkStatus::EnumStatus representing the state of the connection to the given host + */ + virtual int status( const QString & host) = 0; + /** + * Request a connection to the named host, registering the application's usage of this connection + * @param host The hostname the client wants to connect to. + * @param userInitiated Indicates whether the connection is a direct result of a user action or is a background task. Used by the daemon to decide whether to create an on-demand connection. + * @return An NetworkStatus::EnumRequestResult indicating whether the request was accepted + */ + virtual int request( const QString & host, bool userInitiated ) = 0; + /** + * Indicate that a previously registered connection to the given host is no longer needed by this client + * @param host The hostname being relinquished. + */ + virtual void relinquish( const QString & host ) = 0; + /** + * Indicate that a communication failure has occurred for a given host + * @param host The hostname for which the failure occurred. + * @return True indicates the caller should try again to lookup the host, as the daemon has another IP address available. + */ + virtual bool reportFailure( const QString & host ) = 0; + /** + * Utility method to check the daemon's status + */ +k_dcop_signals: + /** + * A status change occurred for the network(s) used to connect to the given host. + * @param host The host which the application has indicated it is using + * @param status The new status of the network used to reach host. + */ + void statusChange( QString host, int status ); + /** + * The network would like to shut down - any clients using this host are to finish using it immediately and call + * relinquish() when done. + * @param host The host, registered as in use by applications, which is about to be disconnected. + */ + void shutdownRequested( QString host ); +}; + +#endif diff --git a/networkstatus/clientifaceimpl.cpp b/networkstatus/clientifaceimpl.cpp new file mode 100644 index 000000000..a5bfb2682 --- /dev/null +++ b/networkstatus/clientifaceimpl.cpp @@ -0,0 +1,51 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "clientifaceimpl.h" + +ClientIfaceImpl::ClientIfaceImpl( NetworkStatusModule * module ) : m_module ( module ) +{ +} + +int ClientIfaceImpl::status( QString host ) +{ + return m_module->status( host ); +} + +int ClientIfaceImpl::request( QString host, bool userInitiated ) +{ + return m_module->request( host, userInitiated ); +} + +void ClientIfaceImpl::relinquish( QString host ) +{ + m_module->relinquish( host ); +} + +bool ClientIfaceImpl::reportFailure( QString host ) +{ + return m_module->reportFailure( host ); +} + +// QString ClientIfaceImpl::statusAsString() +// { +// +// } diff --git a/networkstatus/clientifaceimpl.h b/networkstatus/clientifaceimpl.h new file mode 100644 index 000000000..5bad7afd2 --- /dev/null +++ b/networkstatus/clientifaceimpl.h @@ -0,0 +1,43 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef NETWORKSTATUS_CLIENTIFACEIMPL_H +#define NETWORKSTATUS_CLIENTIFACEIMPL_H + +#include <qstring.h> + +#include "clientiface.h" +#include "networkstatus.h" + +class ClientIfaceImpl : virtual public ClientIface +{ +public: + ClientIfaceImpl( NetworkStatusModule * module ); + int status( QString host ); + int request( QString host, bool userInitiated ); + void relinquish( QString host ); + bool reportFailure( QString host ); +/* QString statusAsString();*/ +private: + NetworkStatusModule * m_module; +}; + +#endif diff --git a/networkstatus/connectionmanager.cpp b/networkstatus/connectionmanager.cpp new file mode 100644 index 000000000..bb98ddf8e --- /dev/null +++ b/networkstatus/connectionmanager.cpp @@ -0,0 +1,156 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <kapplication.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kstaticdeleter.h> + +#include "clientiface_stub.h" +#include "networkstatuscommon.h" + +#include "connectionmanager.h" + +// ConnectionManager's private parts +class ConnectionManagerPrivate +{ + public: + // this holds the currently active state + ConnectionManager::State m_state; + ClientIface_stub * m_stub; + bool m_userInitiatedOnly; +}; + +// Connection manager itself +ConnectionManager::ConnectionManager( QObject * parent, const char * name ) : DCOPObject( "ConnectionManager" ),QObject( parent, name ) +{ + d = new ConnectionManagerPrivate; + + d->m_stub = new ClientIface_stub( kapp->dcopClient(), "kded", "networkstatus" ); + + connectDCOPSignal( "kded", "networkstatus", "statusChange(QString,int)", "slotStatusChanged(QString,int)", false ); + d->m_userInitiatedOnly = false; + initialise(); +} + +ConnectionManager *ConnectionManager::s_self = 0L; + +ConnectionManager *ConnectionManager::self() +{ + static KStaticDeleter<ConnectionManager> deleter; + if(!s_self) + deleter.setObject( s_self, new ConnectionManager( 0, "connection_manager" ) ); + return s_self; +} + +void ConnectionManager::initialise() +{ + // determine initial state and set the state object accordingly. + d->m_state = Offline; + updateStatus(); +} + +void ConnectionManager::updateStatus() +{ + /*NetworkStatus::EnumStatus daemonStatus = (NetworkStatus::EnumStatus)d->m_stub->status( QString::null ); + switch ( daemonStatus ) + { + case Offline: + case OfflineFailed: + case OfflineDisconnected: + case ShuttingDown: + if ( d->m_state == Online ) + d->m_state = Pending; + else + d->m_state = Offline; + break; + case Establishing: + case Online: + d->m_state = Online; + break; + case NoNetworks: + case Unreachable: + d->m_state = Inactive; + break; + }*/ +} + +ConnectionManager::~ConnectionManager() +{ + delete d; +} + +NetworkStatus::EnumStatus ConnectionManager::status( const QString & host ) +{ + if ( d->m_state == Inactive ) + return NetworkStatus::NoNetworks; + else + return NetworkStatus::Offline; +} +NetworkStatus::EnumRequestResult ConnectionManager::requestConnection( QWidget * mainWidget, const QString & host, bool userInitiated ) +{ + NetworkStatus::EnumRequestResult result; + // if offline and the user has previously indicated they didn't want any new connections, suppress it + if ( d->m_state == Offline && !userInitiated && d->m_userInitiatedOnly ) + result = NetworkStatus::UserRefused; + // if offline, ask the user whether this connection should be allowed + if ( d->m_state == Offline ) + { + if ( askToConnect( mainWidget ) ) + result = (NetworkStatus::EnumRequestResult)d->m_stub->request( host, userInitiated ); + else + result = NetworkStatus::UserRefused; + } + // otherwise, just ask for the connection + else + result = (NetworkStatus::EnumRequestResult)d->m_stub->request( host, userInitiated ); + + return result; +} + +void ConnectionManager::relinquishConnection( const QString & host ) +{ + d->m_stub->relinquish( host ); +} + +void ConnectionManager::slotStatusChanged( QString host, int status ) +{ + updateStatus(); + // reset user initiated only flag if we are now online + if ( d->m_state == Online ) + d->m_userInitiatedOnly = false; + + emit statusChanged( host, (NetworkStatus::EnumStatus)status ); +} + +bool ConnectionManager::askToConnect( QWidget * mainWidget ) +{ + i18n( "A network connection was disconnected. The application is now in offline mode. Do you want the application to resume network operations when the network is available again?" ); + i18n( "This application is currently in offline mode. Do you want to connect?" ); + i18n( "Message shown when a network connection failed. The placeholder contains the concrete description of the operation eg 'while performing this operation", "A network connection failed %1. Do you want to place the application in offline mode?" ); + return ( KMessageBox::questionYesNo( mainWidget, + i18n("This application is currently in offline mode. Do you want to connect in order to carry out this operation?"), + i18n("Leave Offline Mode?"), + i18n("Connect"), i18n("Do Not Connect"), + QString::fromLatin1("OfflineModeAlwaysGoOnline") ) == KMessageBox::Yes ); +} + +#include "connectionmanager.moc" diff --git a/networkstatus/connectionmanager.h b/networkstatus/connectionmanager.h new file mode 100644 index 000000000..ab1401575 --- /dev/null +++ b/networkstatus/connectionmanager.h @@ -0,0 +1,57 @@ +/* + connectionmanager.h - Provides the client side interface to the kde networkstatus daemon + + Copyright (c) 2004 by Will Stephenson <lists@stevello.free-online.co.uk> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KDE_CONNECTION_MANAGER_H +#define KDE_CONNECTION_MANAGER_H + +#include <dcopobject.h> + +#include "networkstatuscommon.h" + +class ConnectionManagerPrivate; + +class ConnectionManager : public QObject, virtual public DCOPObject +{ + Q_OBJECT + K_DCOP + public: + static ConnectionManager* self(); + enum State { Inactive, Online, Offline, Pending }; + virtual ~ConnectionManager(); + NetworkStatus::EnumStatus status( const QString & host ); + // check if a hostname is available. Ask user if offline. Request host + NetworkStatus::EnumRequestResult requestConnection( QWidget* mainWidget, const QString & host, bool userInitiated ); + // method to relinquish a connection + void relinquishConnection( const QString & host ); + signals: + // signal that the network for a hostname is up/down + void statusChanged( const QString & host, NetworkStatus::EnumStatus status ); + protected: + // sets up internal state + void initialise(); + // reread the desktop status from the daemon and update internal state + void updateStatus(); + // ask if the user would like to reconnect + bool askToConnect( QWidget * mainWidget ); + k_dcop: + void slotStatusChanged( QString host, int status ); + private: + ConnectionManager( QObject *parent, const char * name ); + ConnectionManagerPrivate *d; + static ConnectionManager * s_self; +}; + +#endif + diff --git a/networkstatus/network.cpp b/networkstatus/network.cpp new file mode 100644 index 000000000..c1aacafc4 --- /dev/null +++ b/networkstatus/network.cpp @@ -0,0 +1,93 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <kdebug.h> + +#include "network.h" + +Network::Network( const QString name, NetworkStatus::Properties properties ) + : m_name( name ) +{ + kdDebug() << k_funcinfo << "constructing network '" << name << "', status: " << properties.status << endl; + m_status = properties.status; + m_netmasks = properties.netmasks; + m_internet = properties.internet; + m_service = properties.service; + m_onDemandPolicy = properties.onDemandPolicy; +} + +NetworkStatus::EnumStatus Network::reachabilityFor( const QString & host ) +{ + // initially assume all networks are internet + // TODO: compute reachability properly + Q_UNUSED( host ); + if ( true /*nss.properties.internet && notPrivateNetwork( host )*/ ) + { + NetworkStatus::EnumStatus status; + if ( m_status == NetworkStatus::Establishing || m_status == NetworkStatus::Online ) + status = NetworkStatus::Online; + else if ( m_status == NetworkStatus::ShuttingDown || m_status == NetworkStatus::Offline ) + status = NetworkStatus::Offline; + else + status = m_status; + + return status; + } +} + +void Network::registerUsage( const QCString appId, const QString host ) +{ + NetworkUsageStruct nus; + nus.appId = appId; + nus.host = host; + NetworkUsageList::iterator end = m_usage.end(); + for ( NetworkUsageList::iterator it = m_usage.begin(); it != end; ++it ) + { + if ( (*it).appId == appId && (*it).host == host ) + return; + } + kdDebug() << k_funcinfo << "registering " << appId << " as using network " << m_name << " for " << host << endl; + m_usage.append( nus ); +} + +void Network::unregisterUsage( const QCString appId, const QString host ) +{ + NetworkUsageList::iterator end = m_usage.end(); + for ( NetworkUsageList::iterator it = m_usage.begin(); it != end; ++it ) + { + if ( (*it).appId == appId && (*it).host == host ) + { + kdDebug() << k_funcinfo << "unregistering " << appId << "'s usage of " << m_name << " for " << host << endl; + m_usage.remove( it ); + break; + } + } +} + +void Network::setStatus( NetworkStatus::EnumStatus status ) +{ + m_status = status; +} + +void Network::removeAllUsage() +{ + m_usage.clear(); +} diff --git a/networkstatus/network.h b/networkstatus/network.h new file mode 100644 index 000000000..c5162f10d --- /dev/null +++ b/networkstatus/network.h @@ -0,0 +1,67 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef NETWORKSTATUS_NETWORK_H +#define NETWORKSTATUS_NETWORK_H + +#include <qstringlist.h> +#include <ksharedptr.h> +#include "networkstatuscommon.h" + +struct NetworkUsageStruct +{ + QCString appId; + QString host; +}; + +typedef QValueList< NetworkUsageStruct > NetworkUsageList; + +class Network +{ +public: + Network( const QString name, NetworkStatus::Properties properties ); + Network( const Network & other ); + NetworkStatus::EnumStatus reachabilityFor( const QString & host ); + void registerUsage( const QCString appId, const QString host ); + void unregisterUsage( const QCString appId, const QString host ); + void setStatus( NetworkStatus::EnumStatus status ); + + void removeAllUsage(); + + NetworkStatus::EnumStatus status() { return m_status; } + QString name() { return m_name; } + bool internet() { return m_internet; } + QStringList netmasks() { return m_netmasks; } + QCString service() { return m_service; } + NetworkStatus::EnumOnDemandPolicy onDemandPolicy() { return m_onDemandPolicy; } + NetworkUsageList usage() { return m_usage; } + +private: + NetworkStatus::EnumStatus m_status; + QString m_name; + bool m_internet; + QStringList m_netmasks; + QCString m_service; + NetworkStatus::EnumOnDemandPolicy m_onDemandPolicy; + NetworkUsageList m_usage; +}; + +#endif diff --git a/networkstatus/networkstatus.cpp b/networkstatus/networkstatus.cpp new file mode 100644 index 000000000..900ac77f5 --- /dev/null +++ b/networkstatus/networkstatus.cpp @@ -0,0 +1,307 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "networkstatus.h" + +#include <qdict.h> +#include <qtimer.h> +#include <qvaluelist.h> + +#include <dcopclient.h> +#include <kapplication.h> +#include <kdebug.h> + +#include "clientifaceimpl.h" +#include "serviceifaceimpl.h" +#include "network.h" +#include <kdepimmacros.h> + +extern "C" { + KDE_EXPORT KDEDModule* create_networkstatus( const QCString& obj ) + { + return new NetworkStatusModule( obj ); + } +} + +// INTERNALLY USED STRUCTS AND TYPEDEFS + +//typedef QDict< Network > NetworkList; +typedef QValueList< Network * > NetworkList; + +class NetworkStatusModule::Private +{ +public: + NetworkList networks; +/* ClientIface * clientIface; + ServiceIface * serviceIface;*/ +}; + +// CTORS/DTORS + +NetworkStatusModule::NetworkStatusModule( const QCString & obj ) : KDEDModule( obj ) +{ + d = new Private; +/* d->clientIface = new ClientIfaceImpl( this ); + d->serviceIface = new ServiceIfaceImpl( this );*/ + connect( kapp->dcopClient(), SIGNAL( applicationRemoved( const QCString& ) ) , this, SLOT( unregisteredFromDCOP( const QCString& ) ) ); + connect( kapp->dcopClient(), SIGNAL( applicationRegistered( const QCString& ) ) , this, SLOT( registeredToDCOP( const QCString& ) ) ); +} + +NetworkStatusModule::~NetworkStatusModule() +{ +/* delete d->clientIface; + delete d->serviceIface;*/ + delete d; +} + +// CLIENT INTERFACE + +QStringList NetworkStatusModule::networks() +{ + kdDebug() << k_funcinfo << " contains " << d->networks.count() << " networks" << endl; + QStringList networks; + NetworkList::iterator end = d->networks.end(); + NetworkList::iterator it = d->networks.begin(); + for ( ; it != end; ++it ) + networks.append( (*it)->name() ); + return networks; +} + +int NetworkStatusModule::status( const QString & host ) +{ + if ( host == "127.0.0.1" || host == "localhost" ) + return NetworkStatus::Online; + Network * p = networkForHost( host ); + if ( !p ) + { + //kdDebug() << k_funcinfo << " no networks have status for host '" << host << "'" << endl; + return (int)NetworkStatus::NoNetworks; + } + else + { + kdDebug() << k_funcinfo << " got status for host '" << host << "' : " << (int)(p->status()) << endl; + return (int)(p->status()); + } +} + +int NetworkStatusModule::request( const QString & host, bool userInitiated ) +{ + // identify most suitable network for host + Network * p = networkForHost( host ); + if ( !p ) + return NetworkStatus::Unavailable; + + NetworkStatus::EnumStatus status = p->status(); + QCString appId = kapp->dcopClient()->senderId(); + if ( status == NetworkStatus::Online ) + { + p->registerUsage( appId, host ); + return NetworkStatus::Connected; + } + // if online + // register usage + // return Available + else if ( status == NetworkStatus::Establishing ) + { + p->registerUsage( appId, host ); + return NetworkStatus::RequestAccepted; + } + // if establishing + // register usage + // return Accepted + else if ( status == NetworkStatus::Offline || status == NetworkStatus::ShuttingDown ) + { + // TODO: check on demand policy + + p->registerUsage( appId, host ); + return NetworkStatus::RequestAccepted; + } + // if offline or ShuttingDown + // check ODP:: + // always or Permanent: register, return accepted + // user: check userInitiated, register, return Accepted or UserRefused + // never: return UserRefused + else if ( status == NetworkStatus::OfflineFailed ) + { + // TODO: check user's preference for dealing with failed networks + p->registerUsage( appId, host ); + return NetworkStatus::RequestAccepted; + } + // if OfflineFailed + // check user's preference + else if ( status == NetworkStatus::OfflineDisconnected ) + { + return NetworkStatus::Unavailable; + } + else + return NetworkStatus::Unavailable; + // if OfflineDisconnected or NoNetworks + // return Unavailable +} + +void NetworkStatusModule::relinquish( const QString & host ) +{ + QCString appId = kapp->dcopClient()->senderId(); + // find network currently used by app for host... + NetworkList::iterator end = d->networks.end(); + NetworkList::iterator it = d->networks.begin(); + for ( ; it != end; ++it ) + { + Network * net = *it; + NetworkUsageList usage = net->usage(); + NetworkUsageList::iterator end2 = usage.end(); + for ( NetworkUsageList::iterator usageIt = usage.begin(); usageIt != end2; ++usageIt ) + { + if ( (*usageIt).appId == appId && (*usageIt).host == host ) + { + // remove host usage record + usage.remove( usageIt ); + // if requested shutdown flagged for network + // check if all hosts have relinquished + // call confirmShutDown on Service + //checkShutdownOk(); + } + } + } +} + +bool NetworkStatusModule::reportFailure( const QString & host ) +{ + // find network for host + // check IP record. remove IP usage record. if other IP exists, return true. + Q_UNUSED( host ); + kdDebug() << k_funcinfo << "NOT IMPLEMENTED" << endl; + return false; +} + +// PROTECTED UTILITY FUNCTIONS +/* + * Determine the network to use for the supplied host + */ +Network * NetworkStatusModule::networkForHost( const QString & host ) const +{ + // return a null pointer if no networks are registered + if ( d->networks.isEmpty() ) + return 0; + + NetworkList::const_iterator it = d->networks.begin(); + Network * bestNetwork = *(it++); + NetworkList::const_iterator end = d->networks.end(); + for ( ; it != end; ++it ) + { + if ( (*it)->reachabilityFor( host ) > bestNetwork->reachabilityFor( host ) ) + { + bestNetwork = (*it); + } + } + return bestNetwork; +} + + +void NetworkStatusModule::registeredToDCOP( const QCString & appId ) +{ +} + +void NetworkStatusModule::unregisteredFromDCOP( const QCString & appId ) +{ + // unregister any networks owned by a service that has just unregistered + NetworkList::iterator it = d->networks.begin(); + NetworkList::iterator end = d->networks.end(); + for ( ; it != end; ++it ) + { + if ( (*it)->service() == appId) + { + kdDebug() << k_funcinfo << "removing '" << (*it)->name() << "', registered by " << appId << endl; + d->networks.remove( it ); + break; + } + } +} + +// SERVICE INTERFACE // +void NetworkStatusModule::setNetworkStatus( const QString & networkName, int st ) +{ + kdDebug() << k_funcinfo << endl; + NetworkStatus::EnumStatus status = (NetworkStatus::EnumStatus)st; + Network * net = 0; + NetworkList::iterator it = d->networks.begin(); + NetworkList::iterator end = d->networks.end(); + for ( ; it != end; ++it ) + { + if ( (*it)->name() == networkName ) + { + net = (*it); + break; + } + } + if ( net ) + { + if ( net->status() == status ) + return; + + // update the status of the network + net->setStatus( status ); + + // notify for each host in use on that network + NetworkUsageList usage = net->usage(); + NetworkUsageList::iterator end = usage.end(); + QStringList notified; + for ( NetworkUsageList::iterator it = usage.begin(); it != end; ++it ) + { + // only notify once per host + if ( !notified.contains( (*it).host ) ) + { + kdDebug() << "notifying statusChange of " << networkName << " to " << (int)status << + " because " << (*it).appId << " is using " << (*it).host << endl; + /*d->clientIface->*/statusChange( (*it).host, (int)status ); + notified.append( (*it).host ); + } + } + + // if we are now anything but Establishing or Online, reset the usage records for that network + if ( !( net->status() == NetworkStatus::Establishing || net->status() == NetworkStatus::Establishing ) ) + net->removeAllUsage(); + } + else + kdDebug() << k_funcinfo << "No network found by this name" << endl; +} + +void NetworkStatusModule::registerNetwork( const QString & networkName, const NetworkStatus::Properties properties ) +{ + kdDebug() << k_funcinfo << "registering '" << networkName << "', with status " << properties.status << endl; + // TODO: check for re-registration, checking appid matches + + d->networks.append( new Network( networkName, properties ) ); +} + +void NetworkStatusModule::unregisterNetwork( const QString & networkName ) +{ + // TODO: check appid + //d->networks.remove( networkName ); +} + +void NetworkStatusModule::requestShutdown( const QString & networkName ) +{ + Q_UNUSED( networkName ); + kdDebug() << k_funcinfo << "NOT IMPLEMENTED" << endl; +} + +#include "networkstatus.moc" diff --git a/networkstatus/networkstatus.desktop b/networkstatus/networkstatus.desktop new file mode 100644 index 000000000..9ebcffeaa --- /dev/null +++ b/networkstatus/networkstatus.desktop @@ -0,0 +1,102 @@ +[Desktop Entry] +Name=Network Status Daemon +Name[af]=Netwerk status bediener +Name[ar]=مراقب القرص و التنفيذ لحالة الشبكة +Name[bg]=Демон за състояние на мрежата +Name[ca]=Dimoni de l'estat de la xarxa +Name[cs]=Démon stavu sítě +Name[da]=Netværkstatusdæmon +Name[de]=Überwachung des Netzwerkstatus +Name[el]=Δαίμονας κατάστασης δικτύου +Name[eo]=Retstat-demono +Name[es]=Daemon de estado de la red +Name[et]=Võrguoleku deemon +Name[eu]=Sarearen egoera deabrua +Name[fa]=شبح وضعیت شبکه +Name[fi]=Verkkotilan tarkkailija +Name[fr]=Suivi de l'état du réseau +Name[fy]=Netwurktastândaemon +Name[gl]=Daemon do Estado da Rede +Name[hu]=Hálózati állapotjelző szolgáltatás +Name[is]=Netstöðupúki +Name[it]=Demone dello stato della rete +Name[ja]=ネットワークステータスデーモン +Name[ka]=ქსელის მდგომარეობის დემონი +Name[kk]=Желі күйінің қызметі +Name[km]=ដេមិនស្ថានភាពបណ្ដាញ +Name[ko]=네트워크 상태 데몬 +Name[lt]=Tinklo statuso tarnyba +Name[mk]=Даемон за мрежен статус +Name[ms]=Daemon Berstatus Rangkaian +Name[nb]=Statusnisse for nettverket +Name[nds]=Nettwarkstatus-Dämoon +Name[ne]=सञ्जाल स्थिति डेइमन +Name[nl]=Netwerkstatusdaemon +Name[nn]=Statusnisse for nettverket +Name[pl]=Usługa stanu sieci +Name[pt]=Servidor de Estado de Rede +Name[pt_BR]=Daemon de Status da Rede +Name[ru]=Служба состояния сети +Name[sk]=Daemon stavu siete +Name[sl]=Demon za omrežno stanje +Name[sr]=Демон за статус мреже +Name[sr@Latn]=Demon za status mreže +Name[sv]=Nätverksstatusdemon +Name[ta]=வலைப்பின்னல் நிலை டெமான் +Name[tr]=Ağ Durum İzleyici +Name[uk]=Демон стану мережі +Name[zh_CN]=网络状态守护程序 +Name[zh_TW]=網路狀態守護程式 +Comment=Tracks status of network interfaces and provides notification to applications using the network. +Comment[af]=Hou tred van die status van netwerk intervlakke en verskaf kennisgewings na programme wat die netwerk gebruik. +Comment[bg]=Следене на състоянието на мрежата и предаване на информацията на програмите, които имат нужда +Comment[ca]=Controla l'estat de les interfícies de xarxa i proporciona notificacions a les aplicacions que usen la xarxa. +Comment[cs]=Zjiš'tuje stav síťových rozhraní a upozorňuje v případě přístupu aplikací k síti. +Comment[da]=Sporer status af netværksgrænseflade og sørger for meddelelser til programmer der bruger netværket. +Comment[de]=Überprüft den Netzwerk-Status und benachrichtigt anfragende Anwendungen +Comment[el]=Παρακολουθεί την κατάσταση του δικτύου και παρέχει ειδοποιήσεις σε εφαρμογές που χρησιμοποιούν το δίκτυο. +Comment[es]=Sigue la pista de las interfaces de red y proporciona notificaciones a las aplicaciones que están usando la red. +Comment[et]=Jälgib võrguliideste olekut ja annab sellest võrgu vahendusel rakendustele teada. +Comment[eu]=Sare interfazeen egoera jarraitzen du eta sarea darabilten aplikazioei jakinarazten die. +Comment[fa]=وضعیت واسطهای شبکه را شیار داده و با استفاده از شبکه، برای کاربردها اخطار فراهم میکند. +Comment[fi]=Tarkkailee verkkoliitäntöjen tilaa ja varoittaa verkkoa käyttäviä sovelluksia. +Comment[fr]=Surveille l'état des interfaces réseaux et fournit des notifications aux applications qui utilisent le réseau +Comment[fy]=Hâldt de tastân by fan de Netwurkynterfaces en hâldt dêr de tapassings fan op de hichte. +Comment[gl]=Monitoriza o estado das interfaces de rede e fornece notificacións ás aplicacións que usen a rede. +Comment[hu]=Figyeli a hálózati csatolók állapotát és értesítési lehetőséget biztosít hálózati alkalmazások számára. +Comment[is]=Fylgist með stöðu netkorta og sendir tilkynningar til forrita sem nota netið. +Comment[it]=Controlla lo stato delle interfacce di rete e fornisce notifiche alle applicazioni che usano al rete. +Comment[ja]=ネットワークインターフェースの状態を追跡し、ネットワークを用いるアプリケーションに通知します +Comment[ka]=იძიებს ქსელის ინტერფეისის სტატუსებს და უზრუნველჰყოფს ქსელის მომხმარებელი პროგრამებისათვის შეტყობინებების მიწოდებას. +Comment[kk]=Желі интерфейстерінің күйін бақылап, желіні қолданатын бағдарламаларын құлақтандыру қызметі. +Comment[km]=តាមដានស្ថានភាពរបស់ចំណុចប្រទាក់បណ្ដាញ ព្រមទាំងផ្ដល់នូវការជូនដំណឹងទៅកម្មវិធី ដែលប្រើបណ្ដាញ ។ +Comment[lt]=Seka tinklo sąsajų būseną ir informuoja apie jas programas, naudojančias tinklą +Comment[mk]=Го следи статусот на мрежните интерфејси и дава известувања на апликациите што ја користат мрежата. +Comment[ms]=Menjejak status antara muka rangkaian dan memberitahu aplikasi yang menggunakan rangkaian tersebut. +Comment[nb]=Overvåker status for nettverksgrensesnitt og varsler programmer som bruker nettverket. +Comment[nds]=Överwacht den Tostand vun Nettwark-Koppelsteden un sendt Narichten na Programmen, de dat Nettwark bruukt. +Comment[ne]=सञ्जाल इन्टरफेसको स्थिति ट्र्याक गर्दछ र सञ्जाल प्रयोग गरेर अनुप्रयोगमा जानकारी उपलब्ध गराउछ । +Comment[nl]=Houdt de status bij van de netwerkinterfaces en houdt daar de toepassingen van op de hoogte. +Comment[nn]=Overvakar status for nettverksgrensesnitt og varslar program som brukar nettverket. +Comment[pl]=Śledzi stan interfejsów sieciowych i powiadamia programy używające sieci. +Comment[pt]=Vigia o estado das interfaces de rede e avisa as aplicações que utilizam a rede. +Comment[pt_BR]=Controla o status das interfaces de rede e fornece notificações para aplicativos utilizando a rede. +Comment[ru]=Служба отслеживания состояния сетевых интерфейсов и обращения приложений к сети. +Comment[sk]=Sleduje stav sieťových rozhraní a poskytuje upozornenia aplikáciám používajúcim sieť. +Comment[sl]=Sledi stanju omrežnim vmesnikom in omogoča obvestila programom, ki uporabljajo omrežje +Comment[sr]=Прати статус мрежних интерфејса и пружа обавештења програмима који користе мрежу. +Comment[sr@Latn]=Prati status mrežnih interfejsa i pruža obaveštenja programima koji koriste mrežu. +Comment[sv]=Bevakar status för nätverksgränssnitt och tillhandahåller underrättelser till program som använder nätverket. +Comment[ta]=வலைப்பின்னலைப் பயன்படுத்தி வலைப்பின்னல் இடைமுகங்களின் நிலையை கண்காணிக்கிறது மற்றும் பயன்பாடுகளுக்கு அறிவிப்பை வழங்குகிறது. +Comment[tr]=Ağ arayüzlerinin durmunu izler ve ağı kullanan uygulamalar için gereken uyarıları sağlar. +Comment[uk]=Слідкує за станом інтерфейсів мережі і сповіщає програми, які користуються мережею. +Comment[zh_CN]=跟踪网卡的状态并为应用程序提供使用网络的通知。 +Comment[zh_TW]=追蹤網路介面的狀態,並提供使用網路的應用程式的通知。 +Type=Service +ServiceTypes=KDEDModule +X-KDE-ModuleType=Library +X-KDE-Library=networkstatus +X-KDE-FactoryName=networkstatus +X-KDE-Kded-autoload=true +X-KDE-Kded-load-on-demand=true + diff --git a/networkstatus/networkstatus.h b/networkstatus/networkstatus.h new file mode 100644 index 000000000..b4281b961 --- /dev/null +++ b/networkstatus/networkstatus.h @@ -0,0 +1,80 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDED_NETWORKSTATUS_H +#define KDED_NETWORKSTATUS_H + +#include "networkstatuscommon.h" + +#include <kdedmodule.h> + +#include "clientiface.h" +#include "network.h" +#include "serviceiface.h" + +struct NetworkStatusStruct; + +class NetworkStatusModule : virtual public KDEDModule/*, public ClientIface, ServiceIface*/ // <-spot the multiple inheritance pb +{ +Q_OBJECT +K_DCOP +public: + NetworkStatusModule( const QCString & obj ); + ~NetworkStatusModule(); +k_dcop: + // Client interface + QStringList networks(); + int status( const QString & host ); + int request( const QString & host, bool userInitiated ); + void relinquish( const QString & host ); + bool reportFailure( const QString & host ); +// QString statusAsString(); + // Service interface + void setNetworkStatus( const QString & networkName, int status ); + void registerNetwork( const QString & networkName, NetworkStatus::Properties properties ); + void unregisterNetwork( const QString & networkName ); + void requestShutdown( const QString & networkName ); +k_dcop_signals: + /** + * A status change occurred for the network(s) used to connect to the given host. + * @param host The host which the application has indicated it is using + * @param status The new status of the network used to reach host. + */ + void statusChange( QString host, int status ); + /** + * The network would like to shut down - any clients using this host are to finish using it immediately and call + * relinquish() when done. + * @param host The host, registered as in use by applications, which is about to be disconnected. + */ + void shutdownRequested( QString host ); +protected slots: + void registeredToDCOP( const QCString& appId ); + void unregisteredFromDCOP( const QCString& appId ); + +protected: + // QStringList networkUsers( const QString & networkName ); + Network * networkForHost( const QString & host ) const; + +private: + class Private; + Private *d; +}; +#endif diff --git a/networkstatus/networkstatus.kdevelop b/networkstatus/networkstatus.kdevelop new file mode 100644 index 000000000..29168abf7 --- /dev/null +++ b/networkstatus/networkstatus.kdevelop @@ -0,0 +1,108 @@ +<?xml version = '1.0'?> +<kdevelop> + <general> + <author>Will Stephenson</author> + <email>wstephenson@suse.de</email> + <version>$VERSION$</version> + <projectmanagement>KDevKDEAutoProject</projectmanagement> + <primarylanguage>C++</primarylanguage> + <keywords> + <keyword>Qt</keyword> + <keyword>KDE</keyword> + </keywords> + </general> + <kdevfileview> + <groups> + <group pattern="*.cpp;*.cxx;*.h" name="Sources" /> + <group pattern="*.ui" name="User Interface" /> + <group pattern="*.png" name="Icons" /> + <group pattern="*.po;*.ts" name="Translations" /> + <group pattern="*" name="Others" /> + <hidenonprojectfiles>false</hidenonprojectfiles> + <hidenonlocation>false</hidenonlocation> + </groups> + <tree> + <hidepatterns>*.o,*.lo,CVS</hidepatterns> + <hidenonprojectfiles>false</hidenonprojectfiles> + </tree> + </kdevfileview> + <kdevdoctreeview> + <ignoretocs> + <toc>ada</toc> + <toc>ada_bugs_gcc</toc> + <toc>bash</toc> + <toc>bash_bugs</toc> + <toc>clanlib</toc> + <toc>fortran_bugs_gcc</toc> + <toc>gnome1</toc> + <toc>gnustep</toc> + <toc>gtk</toc> + <toc>gtk_bugs</toc> + <toc>haskell</toc> + <toc>haskell_bugs_ghc</toc> + <toc>java_bugs_gcc</toc> + <toc>java_bugs_sun</toc> + <toc>opengl</toc> + <toc>pascal_bugs_fp</toc> + <toc>php</toc> + <toc>php_bugs</toc> + <toc>perl</toc> + <toc>perl_bugs</toc> + <toc>python</toc> + <toc>python_bugs</toc> + <toc>ruby</toc> + <toc>ruby_bugs</toc> + <toc>sdl</toc> + <toc>stl</toc> + <toc>sw</toc> + <toc>w3c-dom-level2-html</toc> + <toc>w3c-svg</toc> + <toc>w3c-uaag10</toc> + <toc>wxwidgets_bugs</toc> + </ignoretocs> + <ignoreqt_xml> + <toc>qmake User Guide</toc> + </ignoreqt_xml> + </kdevdoctreeview> + <kdevdebugger> + <general> + <dbgshell>libtool</dbgshell> + </general> + </kdevdebugger> + <kdevfilecreate> + <useglobaltypes> + <type ext="ui" /> + <type ext="cpp" /> + <type ext="h" /> + </useglobaltypes> + </kdevfilecreate> + <kdevautoproject> + <make> + <envvars> + <envvar value="1" name="WANT_AUTOCONF_2_5" /> + <envvar value="1" name="WANT_AUTOMAKE_1_6" /> + </envvars> + </make> + <run> + <directoryradio>executable</directoryradio> + </run> + <general> + <activetarget>kded_networkstatus.la</activetarget> + </general> + </kdevautoproject> + <kdevcppsupport> + <references/> + <codecompletion> + <includeGlobalFunctions>true</includeGlobalFunctions> + <includeTypes>true</includeTypes> + <includeEnums>true</includeEnums> + <includeTypedefs>false</includeTypedefs> + <automaticCodeCompletion>true</automaticCodeCompletion> + <automaticArgumentsHint>true</automaticArgumentsHint> + <automaticHeaderCompletion>true</automaticHeaderCompletion> + <codeCompletionDelay>250</codeCompletionDelay> + <argumentsHintDelay>400</argumentsHintDelay> + <headerCompletionDelay>250</headerCompletionDelay> + </codecompletion> + </kdevcppsupport> +</kdevelop> diff --git a/networkstatus/networkstatuscommon.cpp b/networkstatus/networkstatuscommon.cpp new file mode 100644 index 000000000..db9f137ec --- /dev/null +++ b/networkstatus/networkstatuscommon.cpp @@ -0,0 +1,53 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "networkstatuscommon.h" +#include <kdebug.h> + +QDataStream & operator<< ( QDataStream & s, const NetworkStatus::Properties p ) +{ + kdDebug() << k_funcinfo << "status is: " << (int)p.status << endl; + s << (int)p.status; + s << (int)p.onDemandPolicy; + s << p.service; + s << ( p.internet ? 1 : 0 ); + s << p.netmasks; + return s; +} + +QDataStream & operator>> ( QDataStream & s, NetworkStatus::Properties &p ) +{ + int status, onDemandPolicy, internet; + s >> status; + kdDebug() << k_funcinfo << "status is: " << status << endl; + p.status = ( NetworkStatus::EnumStatus )status; + s >> onDemandPolicy; + p.onDemandPolicy = ( NetworkStatus::EnumOnDemandPolicy )onDemandPolicy; + s >> p.service; + s >> internet; + if ( internet ) + p.internet = true; + else + p.internet = false; + s >> p.netmasks; + kdDebug() << k_funcinfo << "enum converted status is: " << p.status << endl; + return s; +} diff --git a/networkstatus/networkstatuscommon.h b/networkstatus/networkstatuscommon.h new file mode 100644 index 000000000..e26d01688 --- /dev/null +++ b/networkstatus/networkstatuscommon.h @@ -0,0 +1,54 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef NETWORKSTATUS_COMMON_H +#define NETWORKSTATUS_COMMON_H + +#include <qstringlist.h> + +namespace NetworkStatus +{ + enum EnumStatus { NoNetworks = 1, Unreachable, OfflineDisconnected, OfflineFailed, ShuttingDown, Offline, Establishing, Online }; + enum EnumRequestResult { RequestAccepted = 1, Connected, UserRefused, Unavailable }; + enum EnumOnDemandPolicy { All, User, None, Permanent }; + struct Properties + { + QString name; + // status of the network + EnumStatus status; + // policy for on-demand usage as defined by the service + EnumOnDemandPolicy onDemandPolicy; + // identifier for the service + QCString service; + // indicate that the connection is to 'the internet' - similar to default gateway in routing + bool internet; + // list of netmasks that the network connects to - overridden by above internet + QStringList netmasks; + // for future expansion consider + // EnumChargingModel - FlatRate, TimeCharge, VolumeCharged + // EnumLinkStatus - for WLANs - VPOOR, POOR, AVERAGE, GOOD, EXCELLENT + }; +} + +QDataStream & operator>> ( QDataStream & s, NetworkStatus::Properties &p ); +QDataStream & operator<< ( QDataStream & s, const NetworkStatus::Properties p ); + +#endif diff --git a/networkstatus/provideriface.h b/networkstatus/provideriface.h new file mode 100644 index 000000000..f49c276d2 --- /dev/null +++ b/networkstatus/provideriface.h @@ -0,0 +1,42 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef NETWORKSTATUS_PROVIDERIFACE_H +#define NETWORKSTATUS_PROVIDERIFACE_H + +#include <dcopobject.h> +class ProviderIface : virtual public DCOPObject +{ +K_DCOP +k_dcop: + /** @return NetworkStatus::EnumOnlineStatus */ + virtual int status( const QString & network ) = 0; + /** @return NetworkStatus::EnumRequestResult */ + virtual int establish( const QString & network ) = 0; + /** @return NetworkStatus::EnumRequestResult */ + virtual int shutdown( const QString & network ) = 0; + /** fake a failure - go directly to failed */ + virtual void simulateFailure() = 0; + /** fake a network disconnect - go directly to offlinedisconnected */ + virtual void simulateDisconnect() = 0; +}; + +#endif diff --git a/networkstatus/serviceiface.h b/networkstatus/serviceiface.h new file mode 100644 index 000000000..60232d928 --- /dev/null +++ b/networkstatus/serviceiface.h @@ -0,0 +1,51 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDED_NETWORKSTATUS_SERVICEIFACE_H +#define KDED_NETWORKSTATUS_SERVICEIFACE_H + +#include "networkstatuscommon.h" + +#include <dcopobject.h> + +class ServiceIface : virtual public DCOPObject +{ +K_DCOP +k_dcop: + /** Change the status for the given network */ + virtual void setNetworkStatus( const QString & networkName, int status ) = 0; + /** Register or update the properties for a network + NB Check that people don't use this to change status */ + virtual void registerNetwork( const QString & networkName, NetworkStatus::Properties properties ) = 0; + /** + * Indicate that this service is no longer administering the named network + * TODO: Work out the implications to clients of unregistering a network + * - maybe this method needs more parameters to give them a clue. + */ + virtual void unregisterNetwork( const QString & networkName ) = 0; + /** + * Tell the daemon that the service would like to shut down this network connection, + * and to notify clients using it so they can stop using it in a controlled manner + */ + virtual void requestShutdown( const QString & networkName ) = 0; +}; + +#endif diff --git a/networkstatus/serviceifaceimpl.cpp b/networkstatus/serviceifaceimpl.cpp new file mode 100644 index 000000000..fdbc9eec0 --- /dev/null +++ b/networkstatus/serviceifaceimpl.cpp @@ -0,0 +1,46 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "serviceifaceimpl.h" + +ServiceIfaceImpl::ServiceIfaceImpl( NetworkStatusModule * module ) : m_module ( module ) +{ +} + +void ServiceIfaceImpl::setStatus( QString networkName, int status ) +{ + m_module->setStatus( networkName, (NetworkStatus::EnumStatus)status ); +} + +void ServiceIfaceImpl::registerNetwork( QString networkName, NetworkStatus::Properties properties ) +{ + m_module->registerNetwork( networkName, properties ); +} + +void ServiceIfaceImpl::unregisterNetwork( QString networkName ) +{ + m_module->unregisterNetwork( networkName ); +} + +void ServiceIfaceImpl::requestShutdown( QString networkName ) +{ + m_module->requestShutdown( networkName ); +} diff --git a/networkstatus/serviceifaceimpl.h b/networkstatus/serviceifaceimpl.h new file mode 100644 index 000000000..703a15c64 --- /dev/null +++ b/networkstatus/serviceifaceimpl.h @@ -0,0 +1,43 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef NETWORKSTATUS_SERVICEIFACEIMPL_H +#define NETWORKSTATUS_SERVICEIFACEIMPL_H + +#include "networkstatus.h" +#include "serviceiface.h" + +/** + * Glue class linking DCOP skeleton to daemon + */ +class ServiceIfaceImpl : virtual public ServiceIface +{ +public: + ServiceIfaceImpl( NetworkStatusModule * module ); + void setStatus( QString networkName, int status ); + void registerNetwork( QString networkName, NetworkStatus::Properties properties ); + void unregisterNetwork( QString networkName ); + void requestShutdown( QString networkName ); +private: + NetworkStatusModule * m_module; +}; + +#endif diff --git a/networkstatus/testservice.cpp b/networkstatus/testservice.cpp new file mode 100644 index 000000000..a1552d27d --- /dev/null +++ b/networkstatus/testservice.cpp @@ -0,0 +1,101 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <qtimer.h> +#include <dcopclient.h> +#include <kapplication.h> +#include "provideriface.h" + +#include "testservice.h" +#include "serviceiface_stub.h" + +TestService::TestService() : QObject(), DCOPObject("ProviderIface") +{ + kapp->dcopClient()->registerAs("testservice" ); + m_service = new ServiceIface_stub( "kded", "networkstatus" ); + m_status = NetworkStatus::Offline; + NetworkStatus::Properties nsp; + nsp.internet = true; + nsp.name = "test_net"; + nsp.onDemandPolicy = NetworkStatus::All; + nsp.service = kapp->dcopClient()->appId(); + nsp.status = m_status; + m_service->registerNetwork( "test_net", nsp ); +} + +TestService::~TestService() +{ + delete m_service; +} + +int TestService::status( const QString & network ) +{ + Q_UNUSED( network ); + return (int)m_status; +} + +int TestService::establish( const QString & network ) +{ + Q_UNUSED( network ); + m_status = NetworkStatus::Establishing; + m_service->setNetworkStatus( "test_net", (int)m_status ); + m_nextStatus = NetworkStatus::Online; + QTimer::singleShot( 5000, this, SLOT( slotStatusChange() ) ); + return (int)NetworkStatus::RequestAccepted; +} + +int TestService::shutdown( const QString & network ) +{ + Q_UNUSED( network ); + m_status = NetworkStatus::ShuttingDown; + m_service->setNetworkStatus( "test_net", (int)m_status ); + m_nextStatus = NetworkStatus::Offline; + QTimer::singleShot( 5000, this, SLOT( slotStatusChange() ) ); + return (int)NetworkStatus::RequestAccepted; +} + +void TestService::simulateFailure() +{ + m_status = NetworkStatus::OfflineFailed; + m_service->setNetworkStatus( "test_net", (int)m_status ); +} + +void TestService::simulateDisconnect() +{ + m_status = NetworkStatus::OfflineDisconnected; + m_service->setNetworkStatus( "test_net", (int)m_status ); +} + +void TestService::slotStatusChange() +{ + m_status = m_nextStatus; + m_service->setNetworkStatus( "test_net", (int)m_status ); +} + +int main( int argc, char** argv ) +{ + KApplication app(argc, argv, "testdcop"); + TestService * test = new TestService; + Q_UNUSED( test ); + return app.exec(); +} + +#include "testservice.moc" diff --git a/networkstatus/testservice.h b/networkstatus/testservice.h new file mode 100644 index 000000000..202c3e593 --- /dev/null +++ b/networkstatus/testservice.h @@ -0,0 +1,49 @@ +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _TEST_NETWORKSTATUS_SERVICE_H +#define _TEST_NETWORKSTATUS_SERVICE_H + +#include "networkstatuscommon.h" +#include "provideriface.h" + +class ServiceIface_stub; + +class TestService : virtual public QObject, ProviderIface +{ +Q_OBJECT +public: + TestService(); + virtual ~TestService(); + int status( const QString & network ); + int establish( const QString & network ); + int shutdown( const QString & network ); + void simulateFailure(); + void simulateDisconnect(); +protected slots: + void slotStatusChange(); +private: + ServiceIface_stub * m_service; + NetworkStatus::EnumStatus m_status; + NetworkStatus::EnumStatus m_nextStatus; +}; + +#endif |