/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */
#include"Tickler.h"
#ifdef MOZ_USE_WIFI_TICKLER # include "nsComponentManagerUtils.h" # include "nsINamed.h" # include "nsServiceManagerUtils.h" # include "nsThreadUtils.h" # include "prnetdb.h"
# include "mozilla/java/GeckoAppShellWrappers.h" # include "mozilla/jni/Utils.h"
Tickler::~Tickler() { // non main thread uses of the tickler should hold weak // references to it if they must hold a reference at all
MOZ_ASSERT(NS_IsMainThread());
if (mThread) {
mThread->AsyncShutdown();
mThread = nullptr;
}
if (mTimer) mTimer->Cancel(); if (mFD) PR_Close(mFD);
}
nsresult Tickler::Init() { if (!XRE_IsParentProcess()) { return NS_ERROR_FAILURE;
}
if (jni::IsAvailable()) {
java::GeckoAppShell::EnableNetworkNotifications();
}
mFD = PR_OpenUDPSocket(PR_AF_INET); if (!mFD) return NS_ERROR_FAILURE;
// make sure new socket has a ttl of 1 // failure is not fatal.
PRSocketOptionData opt;
opt.option = PR_SockOpt_IpTimeToLive;
opt.value.ip_ttl = 1;
PR_SetSocketOption(mFD, &opt);
nsresult rv = NS_NewNamedThread("wifi tickler", getter_AddRefs(mThread)); if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsITimer> tmpTimer = NS_NewTimer(mThread); if (!tmpTimer) return NS_ERROR_OUT_OF_MEMORY;
if (!mPrefs) mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID); if (mPrefs) {
int32_t val; bool boolVal;
if (NS_SUCCEEDED(
mPrefs->GetBoolPref("network.tickle-wifi.enabled", &boolVal)))
mEnabled = boolVal;
if (NS_SUCCEEDED(
mPrefs->GetIntPref("network.tickle-wifi.duration", &val))) { if (val < 1) val = 1; if (val > 100000) val = 100000;
mDuration = TimeDuration::FromMilliseconds(val);
}
if (NS_SUCCEEDED(mPrefs->GetIntPref("network.tickle-wifi.delay", &val))) { if (val < 1) val = 1; if (val > 1000) val = 1000;
mDelay = static_cast<uint32_t>(val);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.