summaryrefslogtreecommitdiffstats
path: root/hal/gonk/GonkSensorsRegistryInterface.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /hal/gonk/GonkSensorsRegistryInterface.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'hal/gonk/GonkSensorsRegistryInterface.cpp')
-rw-r--r--hal/gonk/GonkSensorsRegistryInterface.cpp213
1 files changed, 213 insertions, 0 deletions
diff --git a/hal/gonk/GonkSensorsRegistryInterface.cpp b/hal/gonk/GonkSensorsRegistryInterface.cpp
new file mode 100644
index 000000000..601dc7a2a
--- /dev/null
+++ b/hal/gonk/GonkSensorsRegistryInterface.cpp
@@ -0,0 +1,213 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 sts=2 et sw=2 tw=80: */
+/* 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 "GonkSensorsRegistryInterface.h"
+#include "GonkSensorsHelpers.h"
+#include "HalLog.h"
+#include <mozilla/UniquePtr.h>
+
+namespace mozilla {
+namespace hal {
+
+using namespace mozilla::ipc;
+
+//
+// GonkSensorsRegistryResultHandler
+//
+
+void
+GonkSensorsRegistryResultHandler::OnError(SensorsError aError)
+{
+ HAL_ERR("Received error code %d", static_cast<int>(aError));
+}
+
+void
+GonkSensorsRegistryResultHandler::RegisterModule(uint32_t aProtocolVersion)
+{ }
+
+void
+GonkSensorsRegistryResultHandler::UnregisterModule()
+{ }
+
+GonkSensorsRegistryResultHandler::~GonkSensorsRegistryResultHandler()
+{ }
+
+//
+// GonkSensorsRegistryModule
+//
+
+GonkSensorsRegistryModule::~GonkSensorsRegistryModule()
+{ }
+
+void
+GonkSensorsRegistryModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
+ DaemonSocketPDU& aPDU,
+ DaemonSocketResultHandler* aRes)
+{
+ static void (GonkSensorsRegistryModule::* const HandleRsp[])(
+ const DaemonSocketPDUHeader&,
+ DaemonSocketPDU&,
+ GonkSensorsRegistryResultHandler*) = {
+ [OPCODE_ERROR] = &GonkSensorsRegistryModule::ErrorRsp,
+ [OPCODE_REGISTER_MODULE] = &GonkSensorsRegistryModule::RegisterModuleRsp,
+ [OPCODE_UNREGISTER_MODULE] = &GonkSensorsRegistryModule::UnregisterModuleRsp
+ };
+
+ if ((aHeader.mOpcode >= MOZ_ARRAY_LENGTH(HandleRsp)) ||
+ !HandleRsp[aHeader.mOpcode]) {
+ HAL_ERR("Sensors registry response opcode %d unknown", aHeader.mOpcode);
+ return;
+ }
+
+ RefPtr<GonkSensorsRegistryResultHandler> res =
+ static_cast<GonkSensorsRegistryResultHandler*>(aRes);
+
+ if (!res) {
+ return; // Return early if no result handler has been set
+ }
+
+ (this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
+}
+
+// Commands
+//
+
+nsresult
+GonkSensorsRegistryModule::RegisterModuleCmd(
+ uint8_t aId, GonkSensorsRegistryResultHandler* aRes)
+{
+ MOZ_ASSERT(NS_IsMainThread());
+
+ UniquePtr<DaemonSocketPDU> pdu =
+ MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_REGISTER_MODULE, 0);
+
+ nsresult rv = PackPDU(aId, *pdu);
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
+ rv = Send(pdu.get(), aRes);
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
+ Unused << pdu.release();
+ return NS_OK;
+}
+
+nsresult
+GonkSensorsRegistryModule::UnregisterModuleCmd(
+ uint8_t aId, GonkSensorsRegistryResultHandler* aRes)
+{
+ MOZ_ASSERT(NS_IsMainThread());
+
+ UniquePtr<DaemonSocketPDU> pdu =
+ MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_UNREGISTER_MODULE, 0);
+
+ nsresult rv = PackPDU(aId, *pdu);
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
+ rv = Send(pdu.get(), aRes);
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
+ Unused << pdu.release();
+ return NS_OK;
+}
+
+// Responses
+//
+
+void
+GonkSensorsRegistryModule::ErrorRsp(
+ const DaemonSocketPDUHeader& aHeader,
+ DaemonSocketPDU& aPDU, GonkSensorsRegistryResultHandler* aRes)
+{
+ ErrorRunnable::Dispatch(
+ aRes, &GonkSensorsRegistryResultHandler::OnError, UnpackPDUInitOp(aPDU));
+}
+
+void
+GonkSensorsRegistryModule::RegisterModuleRsp(
+ const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
+ GonkSensorsRegistryResultHandler* aRes)
+{
+ Uint32ResultRunnable::Dispatch(
+ aRes,
+ &GonkSensorsRegistryResultHandler::RegisterModule,
+ UnpackPDUInitOp(aPDU));
+}
+
+void
+GonkSensorsRegistryModule::UnregisterModuleRsp(
+ const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
+ GonkSensorsRegistryResultHandler* aRes)
+{
+ ResultRunnable::Dispatch(
+ aRes,
+ &GonkSensorsRegistryResultHandler::UnregisterModule,
+ UnpackPDUInitOp(aPDU));
+}
+
+//
+// GonkSensorsRegistryInterface
+//
+
+GonkSensorsRegistryInterface::GonkSensorsRegistryInterface(
+ GonkSensorsRegistryModule* aModule)
+ : mModule(aModule)
+{ }
+
+GonkSensorsRegistryInterface::~GonkSensorsRegistryInterface()
+{ }
+
+void
+GonkSensorsRegistryInterface::RegisterModule(
+ uint8_t aId, GonkSensorsRegistryResultHandler* aRes)
+{
+ MOZ_ASSERT(mModule);
+
+ nsresult rv = mModule->RegisterModuleCmd(aId, aRes);
+ if (NS_FAILED(rv)) {
+ DispatchError(aRes, rv);
+ }
+}
+
+void
+GonkSensorsRegistryInterface::UnregisterModule(
+ uint8_t aId, GonkSensorsRegistryResultHandler* aRes)
+{
+ MOZ_ASSERT(mModule);
+
+ nsresult rv = mModule->UnregisterModuleCmd(aId, aRes);
+ if (NS_FAILED(rv)) {
+ DispatchError(aRes, rv);
+ }
+}
+
+void
+GonkSensorsRegistryInterface::DispatchError(
+ GonkSensorsRegistryResultHandler* aRes, SensorsError aError)
+{
+ DaemonResultRunnable1<GonkSensorsRegistryResultHandler, void,
+ SensorsError, SensorsError>::Dispatch(
+ aRes, &GonkSensorsRegistryResultHandler::OnError,
+ ConstantInitOp1<SensorsError>(aError));
+}
+
+void
+GonkSensorsRegistryInterface::DispatchError(
+ GonkSensorsRegistryResultHandler* aRes, nsresult aRv)
+{
+ SensorsError error;
+
+ if (NS_FAILED(Convert(aRv, error))) {
+ error = SENSORS_ERROR_FAIL;
+ }
+ DispatchError(aRes, error);
+}
+
+} // namespace hal
+} // namespace mozilla