1/* 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef NetworkStateNotifier_h 27#define NetworkStateNotifier_h 28 29#include <wtf/FastAllocBase.h> 30#include <wtf/Noncopyable.h> 31 32#if PLATFORM(MAC) 33 34#include <wtf/RetainPtr.h> 35#include "Timer.h" 36 37typedef const struct __CFArray * CFArrayRef; 38typedef const struct __SCDynamicStore * SCDynamicStoreRef; 39 40#elif PLATFORM(WIN) 41 42#include <windows.h> 43 44#elif PLATFORM(QT) 45 46#include <QtCore/qglobal.h> 47 48#elif PLATFORM(EFL) 49 50typedef struct _Ecore_Fd_Handler Ecore_Fd_Handler; 51typedef unsigned char Eina_Bool; 52 53#endif 54 55namespace WebCore { 56 57#if (PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT)) 58class NetworkStateNotifierPrivate; 59#endif 60 61class NetworkStateNotifier { 62 WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); WTF_MAKE_FAST_ALLOCATED; 63public: 64 NetworkStateNotifier(); 65#if PLATFORM(EFL) 66 ~NetworkStateNotifier(); 67#endif 68 void setNetworkStateChangedFunction(void (*)()); 69 70 bool onLine() const { return m_isOnLine; } 71 72#if (PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT)) 73 void setNetworkAccessAllowed(bool); 74#endif 75 76#if PLATFORM(BLACKBERRY) 77 void networkStateChange(bool online); 78#endif 79 80private: 81 bool m_isOnLine; 82 void (*m_networkStateChangedFunction)(); 83 84 void updateState(); 85 86#if PLATFORM(MAC) 87 void networkStateChangeTimerFired(Timer<NetworkStateNotifier>*); 88 89 static void dynamicStoreCallback(SCDynamicStoreRef, CFArrayRef changedKeys, void *info); 90 91 RetainPtr<SCDynamicStoreRef> m_store; 92 Timer<NetworkStateNotifier> m_networkStateChangeTimer; 93 94#elif PLATFORM(WIN) 95 static void CALLBACK addrChangeCallback(void*, BOOLEAN timedOut); 96 static void callAddressChanged(void*); 97 void addressChanged(); 98 99 void registerForAddressChange(); 100 HANDLE m_waitHandle; 101 OVERLAPPED m_overlapped; 102 103#elif PLATFORM(EFL) 104 void networkInterfaceChanged(); 105 static Eina_Bool readSocketCallback(void* userData, Ecore_Fd_Handler*); 106 107 int m_netlinkSocket; 108 Ecore_Fd_Handler* m_fdHandler; 109 110#elif (PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT)) 111 friend class NetworkStateNotifierPrivate; 112 NetworkStateNotifierPrivate* p; 113#endif 114}; 115 116#if !PLATFORM(MAC) && !PLATFORM(WIN) && !(PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT)) && !PLATFORM(BLACKBERRY) && !PLATFORM(EFL) 117 118inline NetworkStateNotifier::NetworkStateNotifier() 119 : m_isOnLine(true) 120 , m_networkStateChangedFunction(0) 121{ 122} 123 124inline void NetworkStateNotifier::updateState() { } 125 126#endif 127 128NetworkStateNotifier& networkStateNotifier(); 129 130}; 131 132#endif // NetworkStateNotifier_h 133