DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set et sw=2 ts=4: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef NSNOTIFYADDRLISTENER_H_
#define NSNOTIFYADDRLISTENER_H_

#include <windows.h>
#include <winsock2.h>
#include <iptypes.h>
#include "nsINetworkLinkService.h"
#include "nsIRunnable.h"
#include "nsIObserver.h"
#include "nsThreadUtils.h"
#include "nsThreadPool.h"
#include "nsCOMPtr.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Mutex.h"

class nsNotifyAddrListener : public nsINetworkLinkService,
                             public nsIRunnable,
                             public nsIObserver {
  virtual ~nsNotifyAddrListener();

 public:
  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSINETWORKLINKSERVICE
  NS_DECL_NSIRUNNABLE
  NS_DECL_NSIOBSERVER

  nsNotifyAddrListener();

  nsresult Init(void);
  void CheckLinkStatus(void);

 protected:
  class ChangeEvent : public mozilla::Runnable {
   public:
    NS_DECL_NSIRUNNABLE
    ChangeEvent(nsINetworkLinkService* aService, const char* aEventID)
        : Runnable("nsNotifyAddrListener::ChangeEvent"),
          mService(aService),
          mEventID(aEventID) {}

   private:
    nsCOMPtr<nsINetworkLinkService> mService;
    const char* mEventID;
  };

  bool mLinkUp;
  bool mStatusKnown;
  bool mCheckAttempted;

  nsresult Shutdown(void);
  nsresult SendEvent(const char* aEventID);

  DWORD CheckAdaptersAddresses(void);

  // Checks for an Internet Connection Sharing (ICS) gateway.
  bool CheckICSGateway(PIP_ADAPTER_ADDRESSES aAdapter);
  bool CheckICSStatus(PWCHAR aAdapterName);

  // This threadpool only ever holds 1 thread. It is a threadpool and not a
  // regular thread so that we may call shutdownWithTimeout on it.
  nsCOMPtr<nsIThreadPool> mThread;

 private:
  // Returns the new timeout period for coalescing (or INFINITE)
  DWORD nextCoalesceWaitTime();

  // Called for every detected network change
  nsresult NetworkChanged();

  // Figure out the current network identification
  void calculateNetworkId(void);
  bool findMac(char* gateway);

  mozilla::Mutex mMutex;
  nsCString mNetworkId;

  HANDLE mCheckEvent;

  // set true when mCheckEvent means shutdown
  bool mShutdown;

  // This is a checksum of various meta data for all network interfaces
  // considered UP at last check.
  ULONG mIPInterfaceChecksum;

  // start time of the checking
  mozilla::TimeStamp mStartTime;

  // Flag set while coalescing change events
  bool mCoalescingActive;

  // Time stamp for first event during coalescing
  mozilla::TimeStamp mChangeTime;

  // Time stamp of last NS_NETWORK_LINK_DATA_CHANGED event
  mozilla::TimeStamp mNetworkChangeTime;
};

#endif /* NSNOTIFYADDRLISTENER_H_ */