Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/gamepad/ipc/GamepadTestChannelParent.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "GamepadTestChannelParent.h"
8
9
#include "mozilla/dom/GamepadPlatformService.h"
10
#include "mozilla/Unused.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
mozilla::ipc::IPCResult
16
GamepadTestChannelParent::RecvGamepadTestEvent(const uint32_t& aID,
17
                                               const GamepadChangeEvent& aEvent)
18
0
{
19
0
  mozilla::ipc::AssertIsOnBackgroundThread();
20
0
  RefPtr<GamepadPlatformService>  service =
21
0
    GamepadPlatformService::GetParentService();
22
0
  MOZ_ASSERT(service);
23
0
  const uint32_t index = aEvent.index();
24
0
  const GamepadChangeEventBody& body = aEvent.body();
25
0
  if (body.type() == GamepadChangeEventBody::TGamepadAdded) {
26
0
    const GamepadAdded& a = body.get_GamepadAdded();
27
0
    nsCString gamepadID;
28
0
    LossyCopyUTF16toASCII(a.id(), gamepadID);
29
0
    uint32_t index = service->AddGamepad(gamepadID.get(),
30
0
                                         static_cast<GamepadMappingType>(a.mapping()),
31
0
                                         a.hand(),
32
0
                                         a.num_buttons(),
33
0
                                         a.num_axes(),
34
0
                                         a.num_haptics());
35
0
    if (!mShuttingdown) {
36
0
      Unused << SendReplyGamepadIndex(aID, index);
37
0
    }
38
0
    return IPC_OK();
39
0
  }
40
0
  if (body.type() == GamepadChangeEventBody::TGamepadRemoved) {
41
0
    service->RemoveGamepad(index);
42
0
    return IPC_OK();
43
0
  }
44
0
  if (body.type() == GamepadChangeEventBody::TGamepadButtonInformation) {
45
0
    const GamepadButtonInformation& a = body.get_GamepadButtonInformation();
46
0
    service->NewButtonEvent(index, a.button(), a.pressed(), a.touched(),
47
0
                            a.value());
48
0
    return IPC_OK();
49
0
  }
50
0
  if (body.type() == GamepadChangeEventBody::TGamepadAxisInformation) {
51
0
    const GamepadAxisInformation& a = body.get_GamepadAxisInformation();
52
0
    service->NewAxisMoveEvent(index, a.axis(), a.value());
53
0
    return IPC_OK();
54
0
  }
55
0
  if (body.type() == GamepadChangeEventBody::TGamepadPoseInformation) {
56
0
    const GamepadPoseInformation& a = body.get_GamepadPoseInformation();
57
0
    service->NewPoseEvent(index, a.pose_state());
58
0
    return IPC_OK();
59
0
  }
60
0
61
0
  NS_WARNING("Unknown event type.");
62
0
  return IPC_FAIL_NO_REASON(this);
63
0
}
64
65
mozilla::ipc::IPCResult
66
GamepadTestChannelParent::RecvShutdownChannel()
67
0
{
68
0
  mShuttingdown = true;
69
0
  Unused << Send__delete__(this);
70
0
  return IPC_OK();
71
0
}
72
73
} // namespace dom
74
} // namespace mozilla