LCOV - code coverage report
Current view: top level - ipc/dbus - DBusUtils.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 26 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
       2             : /* vim: set ts=2 et sw=2 tw=80: */
       3             : /*
       4             : ** Copyright 2006, The Android Open Source Project
       5             : **
       6             : ** Licensed under the Apache License, Version 2.0 (the "License");
       7             : ** you may not use this file except in compliance with the License.
       8             : ** You may obtain a copy of the License at
       9             : **
      10             : **     http://www.apache.org/licenses/LICENSE-2.0
      11             : **
      12             : ** Unless required by applicable law or agreed to in writing, software
      13             : ** distributed under the License is distributed on an "AS IS" BASIS,
      14             : ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15             : ** See the License for the specific language governing permissions and
      16             : ** limitations under the License.
      17             : */
      18             : 
      19             : #include <dbus/dbus.h>
      20             : #include "DBusUtils.h"
      21             : 
      22             : #undef CHROMIUM_LOG
      23             : #if defined(MOZ_WIDGET_GONK)
      24             : #include <android/log.h>
      25             : #define CHROMIUM_LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk", args);
      26             : #else
      27             : #define CHROMIUM_LOG(args...)  printf(args);
      28             : #endif
      29             : 
      30             : namespace mozilla {
      31             : namespace ipc {
      32             : 
      33             : //
      34             : // DBusMessageRefPtr
      35             : //
      36             : 
      37           0 : DBusMessageRefPtr::DBusMessageRefPtr(DBusMessage* aMsg)
      38           0 :   : mMsg(aMsg)
      39             : {
      40           0 :   if (mMsg) {
      41           0 :     dbus_message_ref(mMsg);
      42             :   }
      43           0 : }
      44             : 
      45           0 : DBusMessageRefPtr::~DBusMessageRefPtr()
      46             : {
      47           0 :   if (mMsg) {
      48           0 :     dbus_message_unref(mMsg);
      49             :   }
      50           0 : }
      51             : 
      52             : //
      53             : // DBusReplyHandler
      54             : //
      55             : 
      56           0 : void DBusReplyHandler::Callback(DBusMessage* aReply, void* aData)
      57             : {
      58           0 :   MOZ_ASSERT(aData);
      59             : 
      60             :   RefPtr<DBusReplyHandler> handler =
      61           0 :     already_AddRefed<DBusReplyHandler>(static_cast<DBusReplyHandler*>(aData));
      62             : 
      63           0 :   handler->Handle(aReply);
      64           0 : }
      65             : 
      66             : //
      67             : // Utility functions
      68             : //
      69             : 
      70             : void
      71           0 : log_and_free_dbus_error(DBusError* err, const char* function, DBusMessage* msg)
      72             : {
      73           0 :   if (msg) {
      74           0 :     CHROMIUM_LOG("%s: D-Bus error in %s: %s (%s)", function,
      75             :                  dbus_message_get_member((msg)), (err)->name, (err)->message);
      76             :   }     else {
      77           0 :     CHROMIUM_LOG("%s: D-Bus error: %s (%s)", __FUNCTION__,
      78             :                  (err)->name, (err)->message);
      79             :   }
      80           0 :   dbus_error_free((err));
      81           0 : }
      82             : 
      83           0 : int dbus_returns_int32(DBusMessage *reply)
      84             : {
      85             :   DBusError err;
      86           0 :   int32_t ret = -1;
      87             : 
      88           0 :   dbus_error_init(&err);
      89           0 :   if (!dbus_message_get_args(reply, &err,
      90             :                              DBUS_TYPE_INT32, &ret,
      91             :                              DBUS_TYPE_INVALID)) {
      92           0 :     LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, reply);
      93             :   }
      94             : 
      95           0 :   return ret;
      96             : }
      97             : 
      98             : }
      99             : }

Generated by: LCOV version 1.13