Skip to content

Commit

Permalink
Bug 1047277 - Hide HAL's logging macros from the public headers and c…
Browse files Browse the repository at this point in the history
…onvert all components to use them. r=dhylands
  • Loading branch information
gabrielesvelto committed Sep 24, 2014
1 parent eac446f commit eee9e26
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 116 deletions.
3 changes: 2 additions & 1 deletion hal/Hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "Hal.h"
#include "HalImpl.h"
#include "HalLog.h"
#include "HalSandbox.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
Expand Down Expand Up @@ -129,7 +130,7 @@ Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
// only the window corresponding to the bottommost process has its
// visibility state set correctly.
if (!id.HasTraveledThroughIPC() && !WindowIsActive(id.GetWindow())) {
HAL_LOG(("Vibrate: Window is inactive, dropping vibrate."));
HAL_LOG("Vibrate: Window is inactive, dropping vibrate.");
return;
}

Expand Down
5 changes: 0 additions & 5 deletions hal/Hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "mozilla/Observer.h"
#include "mozilla/Types.h"
#include "nsTArray.h"
#include "prlog.h"
#include "mozilla/dom/MozPowerManagerBinding.h"
#include "mozilla/dom/battery/Types.h"
#include "mozilla/dom/network/Types.h"
Expand Down Expand Up @@ -47,10 +46,6 @@ typedef Observer<void_t> AlarmObserver;

class WindowIdentifier;

extern PRLogModuleInfo *GetHalLog();
#define HAL_LOG(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, msg)
#define HAL_ERR(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_ERROR, msg)

typedef Observer<int64_t> SystemClockChangeObserver;
typedef Observer<SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;

Expand Down
33 changes: 33 additions & 0 deletions hal/HalLog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et ft=cpp : */
/* 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 mozilla_HalLog_h
#define mozilla_HalLog_h

#include "prlog.h"

/*
* HalLog.h contains internal macros and functions used for logging.
*
* This should be considered a private include and not used in non-HAL code.
* To enable logging in non-debug builds define the PR_FORCE_LOG macro here.
*/

namespace mozilla {

namespace hal {

extern PRLogModuleInfo *GetHalLog();
#define HAL_LOG(...) \
PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, (__VA_ARGS__))
#define HAL_ERR(...) \
PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_ERROR, (__VA_ARGS__))

} // namespace hal

} // namespace mozilla

#endif // mozilla_HalLog_h
2 changes: 1 addition & 1 deletion hal/HalWakeLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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 "mozilla/Hal.h"
#include "Hal.h"
#include "mozilla/HalWakeLock.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
Expand Down
3 changes: 1 addition & 2 deletions hal/fallback/FallbackAlarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ bool
SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
{
if (!sTimer) {
HAL_LOG(("We should have enabled the alarm"));
MOZ_ASSERT(false);
MOZ_ASSERT(false, "We should have enabled the alarm");
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions hal/fallback/FallbackProcessPriority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "Hal.h"
#include "HalLog.h"

using namespace mozilla::hal;

Expand All @@ -15,9 +16,9 @@ SetProcessPriority(int aPid,
ProcessCPUPriority aCPUPriority,
uint32_t aBackgroundLRU)
{
HAL_LOG(("FallbackProcessPriority - SetProcessPriority(%d, %s, %u)\n",
aPid, ProcessPriorityToString(aPriority, aCPUPriority),
aBackgroundLRU));
HAL_LOG("FallbackProcessPriority - SetProcessPriority(%d, %s, %u)\n",
aPid, ProcessPriorityToString(aPriority, aCPUPriority),
aBackgroundLRU);
}

} // hal_impl
Expand Down
5 changes: 3 additions & 2 deletions hal/fallback/FallbackThreadPriority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "Hal.h"
#include "HalLog.h"

using namespace mozilla::hal;

Expand All @@ -12,8 +13,8 @@ namespace hal_impl {
void
SetCurrentThreadPriority(ThreadPriority aPriority)
{
HAL_LOG(("FallbackThreadPriority - SetCurrentThreadPriority(%d)\n",
ThreadPriorityToString(aPriority)));
HAL_LOG("FallbackThreadPriority - SetCurrentThreadPriority(%d)\n",
ThreadPriorityToString(aPriority));
}

} // hal_impl
Expand Down
5 changes: 2 additions & 3 deletions hal/gonk/GonkDiskSpaceWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ GonkDiskSpaceWatcher::DoStart()
if (mFd == -1) {
NS_WARNING("Error calling inotify_init()");
if (errno == ENOSYS) {
printf_stderr("Warning: No fanotify support in this device's kernel.\n");
NS_WARNING("Warning: No fanotify support in this device's kernel.\n");
}
return;
}
Expand Down Expand Up @@ -241,8 +241,7 @@ GonkDiskSpaceWatcher::OnFileCanReadWithoutBlocking(int aFd)

// We should get an exact multiple of fanotify_event_metadata
if (len <= 0 || (len % FAN_EVENT_METADATA_LEN != 0)) {
printf_stderr("About to crash: fanotify_event_metadata read error.");
MOZ_CRASH();
MOZ_CRASH("About to crash: fanotify_event_metadata read error.");
}

fem = reinterpret_cast<fanotify_event_metadata *>(buf);
Expand Down
47 changes: 24 additions & 23 deletions hal/gonk/GonkFMRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "Hal.h"
#include "HalLog.h"
#include "tavarua.h"
#include "nsThreadUtils.h"
#include "mozilla/FileUtils.h"
Expand Down Expand Up @@ -113,20 +114,20 @@ initMsmFMRadio(hal::FMRadioSettings &aInfo)

rc = setControl(V4L2_CID_PRIVATE_TAVARUA_STATE, FM_RECV);
if (rc < 0) {
HAL_LOG(("Unable to turn on radio |%s|", strerror(errno)));
HAL_LOG("Unable to turn on radio |%s|", strerror(errno));
return;
}

int preEmphasis = aInfo.preEmphasis() <= 50;
rc = setControl(V4L2_CID_PRIVATE_TAVARUA_EMPHASIS, preEmphasis);
if (rc) {
HAL_LOG(("Unable to configure preemphasis"));
HAL_LOG("Unable to configure preemphasis");
return;
}

rc = setControl(V4L2_CID_PRIVATE_TAVARUA_RDS_STD, 0);
if (rc) {
HAL_LOG(("Unable to configure RDS"));
HAL_LOG("Unable to configure RDS");
return;
}

Expand All @@ -142,13 +143,13 @@ initMsmFMRadio(hal::FMRadioSettings &aInfo)
spacing = FM_CH_SPACE_200KHZ;
break;
default:
HAL_LOG(("Unsupported space value - %d", aInfo.spaceType()));
HAL_LOG("Unsupported space value - %d", aInfo.spaceType());
return;
}

rc = setControl(V4L2_CID_PRIVATE_TAVARUA_SPACING, spacing);
if (rc) {
HAL_LOG(("Unable to configure spacing"));
HAL_LOG("Unable to configure spacing");
return;
}

Expand All @@ -166,13 +167,13 @@ initMsmFMRadio(hal::FMRadioSettings &aInfo)
tuner.audmode = V4L2_TUNER_MODE_STEREO;
rc = ioctl(fd, VIDIOC_S_TUNER, &tuner);
if (rc < 0) {
HAL_LOG(("Unable to adjust band limits"));
HAL_LOG("Unable to adjust band limits");
return;
}

rc = setControl(V4L2_CID_PRIVATE_TAVARUA_REGION, TAVARUA_REGION_OTHER);
if (rc < 0) {
HAL_LOG(("Unable to configure region"));
HAL_LOG("Unable to configure region");
return;
}

Expand All @@ -185,7 +186,7 @@ initMsmFMRadio(hal::FMRadioSettings &aInfo)
rc = setControl(V4L2_CID_PRIVATE_TAVARUA_SET_AUDIO_PATH,
noAnalog ? FM_DIGITAL_PATH : FM_ANALOG_PATH);
if (rc < 0) {
HAL_LOG(("Unable to set audio path"));
HAL_LOG("Unable to set audio path");
return;
}

Expand Down Expand Up @@ -272,7 +273,7 @@ void
EnableFMRadio(const hal::FMRadioSettings& aInfo)
{
if (sRadioEnabled) {
HAL_LOG(("Radio already enabled!"));
HAL_LOG("Radio already enabled!");
return;
}

Expand All @@ -282,31 +283,31 @@ EnableFMRadio(const hal::FMRadioSettings& aInfo)

mozilla::ScopedClose fd(open("/dev/radio0", O_RDWR));
if (fd < 0) {
HAL_LOG(("Unable to open radio device"));
HAL_LOG("Unable to open radio device");
hal::NotifyFMRadioStatus(info);
return;
}

struct v4l2_capability cap;
int rc = ioctl(fd, VIDIOC_QUERYCAP, &cap);
if (rc < 0) {
HAL_LOG(("Unable to query radio device"));
HAL_LOG("Unable to query radio device");
hal::NotifyFMRadioStatus(info);
return;
}

sMsmFMMode = !strcmp((char *)cap.driver, "radio-tavarua") ||
!strcmp((char *)cap.driver, "radio-iris");
HAL_LOG(("Radio: %s (%s)\n", cap.driver, cap.card));
HAL_LOG("Radio: %s (%s)\n", cap.driver, cap.card);

if (!(cap.capabilities & V4L2_CAP_RADIO)) {
HAL_LOG(("/dev/radio0 isn't a radio"));
HAL_LOG("/dev/radio0 isn't a radio");
hal::NotifyFMRadioStatus(info);
return;
}

if (!(cap.capabilities & V4L2_CAP_TUNER)) {
HAL_LOG(("/dev/radio0 doesn't support the tuner interface"));
HAL_LOG("/dev/radio0 doesn't support the tuner interface");
hal::NotifyFMRadioStatus(info);
return;
}
Expand All @@ -316,7 +317,7 @@ EnableFMRadio(const hal::FMRadioSettings& aInfo)
sRadioFD = fd.forget();
sMsmFMVersion = cap.version;
if (pthread_create(&sRadioThread, nullptr, runMsmFMRadio, nullptr)) {
HAL_LOG(("Couldn't create radio thread"));
HAL_LOG("Couldn't create radio thread");
hal::NotifyFMRadioStatus(info);
}
return;
Expand All @@ -329,7 +330,7 @@ EnableFMRadio(const hal::FMRadioSettings& aInfo)
tuner.audmode = V4L2_TUNER_MODE_STEREO;
rc = ioctl(fd, VIDIOC_S_TUNER, &tuner);
if (rc < 0) {
HAL_LOG(("Unable to adjust band limits"));
HAL_LOG("Unable to adjust band limits");
}

int emphasis;
Expand All @@ -349,7 +350,7 @@ EnableFMRadio(const hal::FMRadioSettings& aInfo)
}
rc = setControl(V4L2_CID_TUNE_DEEMPHASIS, emphasis);
if (rc < 0) {
HAL_LOG(("Unable to configure deemphasis"));
HAL_LOG("Unable to configure deemphasis");
}

sRadioFD = fd.forget();
Expand All @@ -370,7 +371,7 @@ DisableFMRadio()
if (sMsmFMMode) {
int rc = setControl(V4L2_CID_PRIVATE_TAVARUA_STATE, FM_OFF);
if (rc < 0) {
HAL_LOG(("Unable to turn off radio"));
HAL_LOG("Unable to turn off radio");
}

pthread_join(sRadioThread, nullptr);
Expand Down Expand Up @@ -408,7 +409,7 @@ FMRadioSeek(const hal::FMRadioSeekDirection& aDirection)
hal::FM_RADIO_OPERATION_STATUS_SUCCESS));

if (rc < 0) {
HAL_LOG(("Could not initiate hardware seek"));
HAL_LOG("Could not initiate hardware seek");
return;
}

Expand All @@ -426,7 +427,7 @@ GetFMRadioSettings(hal::FMRadioSettings* aInfo)
struct v4l2_tuner tuner = {0};
int rc = ioctl(sRadioFD, VIDIOC_G_TUNER, &tuner);
if (rc < 0) {
HAL_LOG(("Could not query fm radio for settings"));
HAL_LOG("Could not query fm radio for settings");
return;
}

Expand All @@ -443,7 +444,7 @@ SetFMRadioFrequency(const uint32_t frequency)

int rc = ioctl(sRadioFD, VIDIOC_S_FREQUENCY, &freq);
if (rc < 0)
HAL_LOG(("Could not set radio frequency"));
HAL_LOG("Could not set radio frequency");

if (sMsmFMMode && rc >= 0)
return;
Expand All @@ -463,7 +464,7 @@ GetFMRadioFrequency()
struct v4l2_frequency freq;
int rc = ioctl(sRadioFD, VIDIOC_G_FREQUENCY, &freq);
if (rc < 0) {
HAL_LOG(("Could not get radio frequency"));
HAL_LOG("Could not get radio frequency");
return 0;
}

Expand All @@ -482,7 +483,7 @@ GetFMRadioSignalStrength()
struct v4l2_tuner tuner = {0};
int rc = ioctl(sRadioFD, VIDIOC_G_TUNER, &tuner);
if (rc < 0) {
HAL_LOG(("Could not query fm radio for signal strength"));
HAL_LOG("Could not query fm radio for signal strength");
return 0;
}

Expand Down
Loading

0 comments on commit eee9e26

Please sign in to comment.