diff --git a/dom/fmradio/ipc/FMRadioChild.cpp b/dom/fmradio/ipc/FMRadioChild.cpp new file mode 100644 index 000000000000..b6ebb9b67ab8 --- /dev/null +++ b/dom/fmradio/ipc/FMRadioChild.cpp @@ -0,0 +1,182 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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 "FMRadioChild.h" +#include "mozilla/dom/ContentChild.h" +#include "mozilla/dom/FMRadioRequestChild.h" + +using namespace mozilla::hal; + +BEGIN_FMRADIO_NAMESPACE + +StaticAutoPtr FMRadioChild::sFMRadioChild; + +FMRadioChild::FMRadioChild() + : mEnabled(false) + , mFrequency(0) + , mObserverList(FMRadioEventObserverList()) +{ + MOZ_COUNT_CTOR(FMRadioChild); + + ContentChild::GetSingleton()->SendPFMRadioConstructor(this); + + StatusInfo statusInfo; + SendGetStatusInfo(&statusInfo); + + mEnabled = statusInfo.enabled(); + mFrequency = statusInfo.frequency(); + mUpperBound = statusInfo.upperBound(); + mLowerBound= statusInfo.lowerBound(); + mChannelWidth = statusInfo.channelWidth(); +} + +FMRadioChild::~FMRadioChild() +{ + MOZ_COUNT_DTOR(FMRadioChild); +} + +bool +FMRadioChild::IsEnabled() const +{ + return mEnabled; +} + +double +FMRadioChild::GetFrequency() const +{ + return mFrequency; +} + + +double +FMRadioChild::GetFrequencyUpperBound() const +{ + return mUpperBound; +} + +double +FMRadioChild::GetFrequencyLowerBound() const +{ + return mLowerBound; +} + +double +FMRadioChild::GetChannelWidth() const +{ + return mChannelWidth; +} + +void +FMRadioChild::Enable(double aFrequency, ReplyRunnable* aReplyRunnable) +{ + SendRequest(aReplyRunnable, EnableRequestArgs(aFrequency)); +} + +void +FMRadioChild::Disable(ReplyRunnable* aReplyRunnable) +{ + SendRequest(aReplyRunnable, DisableRequestArgs()); +} + +void +FMRadioChild::SetFrequency(double aFrequency, + ReplyRunnable* aReplyRunnable) +{ + SendRequest(aReplyRunnable, SetFrequencyRequestArgs(aFrequency)); +} + +void +FMRadioChild::Seek(FMRadioSeekDirection aDirection, ReplyRunnable* aReplyRunnable) +{ + SendRequest(aReplyRunnable, SeekRequestArgs(aDirection)); +} + +void +FMRadioChild::CancelSeek(ReplyRunnable* aReplyRunnable) +{ + SendRequest(aReplyRunnable, CancelSeekRequestArgs()); +} + +inline void +FMRadioChild::NotifyFMRadioEvent(FMRadioEventType aType) +{ + mObserverList.Broadcast(aType); +} + +void +FMRadioChild::AddObserver(FMRadioEventObserver* aObserver) +{ + mObserverList.AddObserver(aObserver); +} + +void +FMRadioChild::RemoveObserver(FMRadioEventObserver* aObserver) +{ + mObserverList.RemoveObserver(aObserver); +} + +void +FMRadioChild::SendRequest(ReplyRunnable* aReplyRunnable, + FMRadioRequestArgs aArgs) +{ + PFMRadioRequestChild* childRequest = new FMRadioRequestChild(aReplyRunnable); + SendPFMRadioRequestConstructor(childRequest, aArgs); +} + +bool +FMRadioChild::RecvNotifyFrequencyChanged(const double& aFrequency) +{ + mFrequency = aFrequency; + NotifyFMRadioEvent(FrequencyChanged); + return true; +} + +bool +FMRadioChild::RecvNotifyEnabledChanged(const bool& aEnabled, + const double& aFrequency) +{ + mEnabled = aEnabled; + mFrequency = aFrequency; + NotifyFMRadioEvent(EnabledChanged); + return true; +} + +bool +FMRadioChild::Recv__delete__() +{ + return true; +} + +PFMRadioRequestChild* +FMRadioChild::AllocPFMRadioRequestChild(const FMRadioRequestArgs& aArgs) +{ + MOZ_CRASH(); + return nullptr; +} + +bool +FMRadioChild::DeallocPFMRadioRequestChild(PFMRadioRequestChild* aActor) +{ + delete aActor; + return true; +} + +// static +FMRadioChild* +FMRadioChild::Singleton() +{ + MOZ_ASSERT(XRE_GetProcessType() != GeckoProcessType_Default); + MOZ_ASSERT(NS_IsMainThread()); + + if (!sFMRadioChild) { + sFMRadioChild = new FMRadioChild(); + } + + return sFMRadioChild; +} + +END_FMRADIO_NAMESPACE + diff --git a/dom/fmradio/ipc/FMRadioChild.h b/dom/fmradio/ipc/FMRadioChild.h new file mode 100644 index 000000000000..5367017800e8 --- /dev/null +++ b/dom/fmradio/ipc/FMRadioChild.h @@ -0,0 +1,91 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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/. */ + +#ifndef mozilla_dom_fmradiochild_h__ +#define mozilla_dom_fmradiochild_h__ + +#include "FMRadioCommon.h" +#include "FMRadioService.h" +#include "mozilla/dom/PFMRadioChild.h" +#include "mozilla/StaticPtr.h" + +BEGIN_FMRADIO_NAMESPACE + +/** + * FMRadioChild plays two roles: + * - Kind of proxy of FMRadioService + * Redirect all the requests coming from web content to FMRadioService + * in parent through IPC channel. + * - Child Actor of PFMRadio + * IPC channel to transfer the requests. + */ +class FMRadioChild MOZ_FINAL : public IFMRadioService + , public PFMRadioChild +{ +public: + static FMRadioChild* Singleton(); + ~FMRadioChild(); + + void SendRequest(ReplyRunnable* aReplyRunnable, FMRadioRequestArgs aArgs); + + /* IFMRadioService */ + virtual bool IsEnabled() const MOZ_OVERRIDE; + virtual double GetFrequency() const MOZ_OVERRIDE; + virtual double GetFrequencyUpperBound() const MOZ_OVERRIDE; + virtual double GetFrequencyLowerBound() const MOZ_OVERRIDE; + virtual double GetChannelWidth() const MOZ_OVERRIDE; + + virtual void Enable(double aFrequency, ReplyRunnable* aReplyRunnable) MOZ_OVERRIDE; + virtual void Disable(ReplyRunnable* aReplyRunnable) MOZ_OVERRIDE; + virtual void SetFrequency(double frequency, + ReplyRunnable* aReplyRunnable) MOZ_OVERRIDE; + virtual void Seek(mozilla::hal::FMRadioSeekDirection aDirection, + ReplyRunnable* aReplyRunnable) MOZ_OVERRIDE; + virtual void CancelSeek(ReplyRunnable* aReplyRunnable) MOZ_OVERRIDE; + + virtual void AddObserver(FMRadioEventObserver* aObserver) MOZ_OVERRIDE; + virtual void RemoveObserver(FMRadioEventObserver* aObserver) MOZ_OVERRIDE; + + /* PFMRadioChild */ + virtual bool + Recv__delete__() MOZ_OVERRIDE; + + virtual bool + RecvNotifyFrequencyChanged(const double& aFrequency) MOZ_OVERRIDE; + + virtual bool + RecvNotifyEnabledChanged(const bool& aEnabled, + const double& aFrequency) MOZ_OVERRIDE; + + virtual PFMRadioRequestChild* + AllocPFMRadioRequestChild(const FMRadioRequestArgs& aArgs) MOZ_OVERRIDE; + + virtual bool + DeallocPFMRadioRequestChild(PFMRadioRequestChild* aActor) MOZ_OVERRIDE; + +private: + FMRadioChild(); + + void Init(); + + inline void NotifyFMRadioEvent(FMRadioEventType aType); + + bool mEnabled; + double mFrequency; + double mUpperBound; + double mLowerBound; + double mChannelWidth; + + FMRadioEventObserverList mObserverList; + +private: + static StaticAutoPtr sFMRadioChild; +}; + +END_FMRADIO_NAMESPACE + +#endif // mozilla_dom_fmradiochild_h__ + diff --git a/dom/fmradio/ipc/FMRadioParent.cpp b/dom/fmradio/ipc/FMRadioParent.cpp new file mode 100644 index 000000000000..cf2ad36565d1 --- /dev/null +++ b/dom/fmradio/ipc/FMRadioParent.cpp @@ -0,0 +1,101 @@ +/* -*- 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 "FMRadioParent.h" +#include "mozilla/unused.h" +#include "mozilla/dom/ContentParent.h" +#include "FMRadioRequestParent.h" +#include "FMRadioService.h" + +BEGIN_FMRADIO_NAMESPACE + +FMRadioParent::FMRadioParent() +{ + MOZ_COUNT_CTOR(FMRadioParent); + + IFMRadioService::Singleton()->AddObserver(this); +} + +FMRadioParent::~FMRadioParent() +{ + MOZ_COUNT_DTOR(FMRadioParent); + + IFMRadioService::Singleton()->RemoveObserver(this); +} + +bool +FMRadioParent::RecvGetStatusInfo(StatusInfo* aStatusInfo) +{ + aStatusInfo->enabled() = IFMRadioService::Singleton()->IsEnabled(); + aStatusInfo->frequency() = IFMRadioService::Singleton()->GetFrequency(); + aStatusInfo->upperBound() = + IFMRadioService::Singleton()->GetFrequencyUpperBound(); + aStatusInfo->lowerBound() = + IFMRadioService::Singleton()->GetFrequencyLowerBound(); + aStatusInfo->channelWidth() = + IFMRadioService::Singleton()->GetChannelWidth(); + return true; +} + +PFMRadioRequestParent* +FMRadioParent::AllocPFMRadioRequestParent(const FMRadioRequestArgs& aArgs) +{ + nsRefPtr requestParent = new FMRadioRequestParent(); + + switch (aArgs.type()) { + case FMRadioRequestArgs::TEnableRequestArgs: + IFMRadioService::Singleton()->Enable( + aArgs.get_EnableRequestArgs().frequency(), requestParent); + break; + case FMRadioRequestArgs::TDisableRequestArgs: + IFMRadioService::Singleton()->Disable(requestParent); + break; + case FMRadioRequestArgs::TSetFrequencyRequestArgs: + IFMRadioService::Singleton()->SetFrequency( + aArgs.get_SetFrequencyRequestArgs().frequency(), requestParent); + break; + case FMRadioRequestArgs::TSeekRequestArgs: + IFMRadioService::Singleton()->Seek( + aArgs.get_SeekRequestArgs().direction(), requestParent); + break; + case FMRadioRequestArgs::TCancelSeekRequestArgs: + IFMRadioService::Singleton()->CancelSeek(requestParent); + break; + default: + MOZ_CRASH(); + } + + return requestParent.forget().get(); +} + +bool +FMRadioParent::DeallocPFMRadioRequestParent(PFMRadioRequestParent* aActor) +{ + FMRadioRequestParent* parent = static_cast(aActor); + NS_RELEASE(parent); + return true; +} + +void +FMRadioParent::Notify(const FMRadioEventType& aType) +{ + switch (aType) { + case FrequencyChanged: + unused << SendNotifyFrequencyChanged( + IFMRadioService::Singleton()->GetFrequency()); + break; + case EnabledChanged: + unused << SendNotifyEnabledChanged( + IFMRadioService::Singleton()->IsEnabled(), + IFMRadioService::Singleton()->GetFrequency()); + break; + default: + NS_RUNTIMEABORT("not reached"); + break; + } +} + +END_FMRADIO_NAMESPACE + diff --git a/dom/fmradio/ipc/FMRadioParent.h b/dom/fmradio/ipc/FMRadioParent.h new file mode 100644 index 000000000000..73aba59cb902 --- /dev/null +++ b/dom/fmradio/ipc/FMRadioParent.h @@ -0,0 +1,41 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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/. */ + +#ifndef mozilla_dom_fmradioparent_h__ +#define mozilla_dom_fmradioparent_h__ + +#include "FMRadioCommon.h" +#include "mozilla/dom/PFMRadioParent.h" +#include "mozilla/HalTypes.h" + +BEGIN_FMRADIO_NAMESPACE + +class PFMRadioRequestParent; + +class FMRadioParent MOZ_FINAL : public PFMRadioParent + , public FMRadioEventObserver +{ +public: + FMRadioParent(); + ~FMRadioParent(); + + virtual bool + RecvGetStatusInfo(StatusInfo* aStatusInfo) MOZ_OVERRIDE; + + virtual PFMRadioRequestParent* + AllocPFMRadioRequestParent(const FMRadioRequestArgs& aArgs) MOZ_OVERRIDE; + + virtual bool + DeallocPFMRadioRequestParent(PFMRadioRequestParent* aActor) MOZ_OVERRIDE; + + /* FMRadioEventObserver */ + virtual void Notify(const FMRadioEventType& aType) MOZ_OVERRIDE; +}; + +END_FMRADIO_NAMESPACE + +#endif // mozilla_dom_fmradioparent_h__ + diff --git a/dom/fmradio/ipc/FMRadioRequestChild.cpp b/dom/fmradio/ipc/FMRadioRequestChild.cpp new file mode 100644 index 000000000000..5b4411714fc9 --- /dev/null +++ b/dom/fmradio/ipc/FMRadioRequestChild.cpp @@ -0,0 +1,33 @@ +/* -*- 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 "mozilla/dom/PFMRadioRequestChild.h" +#include "FMRadioRequestChild.h" +#include "FMRadioService.h" + +BEGIN_FMRADIO_NAMESPACE + +FMRadioRequestChild::FMRadioRequestChild(ReplyRunnable* aReplyRunnable) + : mReplyRunnable(aReplyRunnable) +{ + MOZ_COUNT_CTOR(FMRadioRequestChild); +} + +FMRadioRequestChild::~FMRadioRequestChild() +{ + MOZ_COUNT_DTOR(FMRadioRequestChild); +} + +bool +FMRadioRequestChild::Recv__delete__(const FMRadioResponseType& aType) +{ + mReplyRunnable->SetReply(aType); + NS_DispatchToMainThread(mReplyRunnable); + + return true; +} + +END_FMRADIO_NAMESPACE + diff --git a/dom/fmradio/ipc/FMRadioRequestChild.h b/dom/fmradio/ipc/FMRadioRequestChild.h new file mode 100644 index 000000000000..e9cf7335e0ac --- /dev/null +++ b/dom/fmradio/ipc/FMRadioRequestChild.h @@ -0,0 +1,34 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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/. */ + +#ifndef mozilla_dom_fmradiorequestchild_h__ +#define mozilla_dom_fmradiorequestchild_h__ + +#include "FMRadioCommon.h" +#include "mozilla/dom/PFMRadioRequestChild.h" +#include "DOMRequest.h" + +BEGIN_FMRADIO_NAMESPACE + +class ReplyRunnable; + +class FMRadioRequestChild MOZ_FINAL : public PFMRadioRequestChild +{ +public: + FMRadioRequestChild(ReplyRunnable* aReplyRunnable); + ~FMRadioRequestChild(); + + virtual bool + Recv__delete__(const FMRadioResponseType& aResponse) MOZ_OVERRIDE; + +private: + nsRefPtr mReplyRunnable; +}; + +END_FMRADIO_NAMESPACE + +#endif // mozilla_dom_fmradiorequestchild_h__ + diff --git a/dom/fmradio/ipc/FMRadioRequestParent.cpp b/dom/fmradio/ipc/FMRadioRequestParent.cpp new file mode 100644 index 000000000000..37f483a7939e --- /dev/null +++ b/dom/fmradio/ipc/FMRadioRequestParent.cpp @@ -0,0 +1,43 @@ +/* -*- 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 "FMRadioRequestParent.h" +#include "FMRadioService.h" +#include "mozilla/unused.h" +#include "mozilla/dom/PFMRadio.h" + +BEGIN_FMRADIO_NAMESPACE + +FMRadioRequestParent::FMRadioRequestParent() + : mActorDestroyed(false) +{ + MOZ_COUNT_CTOR(FMRadioRequestParent); +} + +FMRadioRequestParent::~FMRadioRequestParent() +{ + MOZ_COUNT_DTOR(FMRadioRequestParent); +} + +void +FMRadioRequestParent::ActorDestroy(ActorDestroyReason aWhy) +{ + mActorDestroyed = true; +} + +nsresult +FMRadioRequestParent::Run() +{ + MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); + + if (!mActorDestroyed) { + unused << Send__delete__(this, mResponseType); + } + + return NS_OK; +} + +END_FMRADIO_NAMESPACE + diff --git a/dom/fmradio/ipc/FMRadioRequestParent.h b/dom/fmradio/ipc/FMRadioRequestParent.h new file mode 100644 index 000000000000..913a0c032885 --- /dev/null +++ b/dom/fmradio/ipc/FMRadioRequestParent.h @@ -0,0 +1,34 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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/. */ + +#ifndef mozilla_dom_fmradiorequestparent_h__ +#define mozilla_dom_fmradiorequestparent_h__ + +#include "FMRadioCommon.h" +#include "mozilla/dom/PFMRadioRequestParent.h" +#include "FMRadioService.h" + +BEGIN_FMRADIO_NAMESPACE + +class FMRadioRequestParent MOZ_FINAL : public PFMRadioRequestParent + , public ReplyRunnable +{ +public: + FMRadioRequestParent(); + ~FMRadioRequestParent(); + + virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; + + NS_IMETHOD Run(); + +private: + bool mActorDestroyed; +}; + +END_FMRADIO_NAMESPACE + +#endif // mozilla_dom_fmradiorequestparent_h__ + diff --git a/dom/fmradio/ipc/Makefile.in b/dom/fmradio/ipc/Makefile.in new file mode 100644 index 000000000000..9041592caaf4 --- /dev/null +++ b/dom/fmradio/ipc/Makefile.in @@ -0,0 +1,22 @@ +# 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/. + +DEPTH = @DEPTH@ +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +LIBRARY_NAME = domfmradio_s + +LOCAL_INCLUDES += \ + -I$(topsrcdir)/dom/fmradio \ + $(NULL) + +include $(topsrcdir)/dom/dom-config.mk + +include $(topsrcdir)/config/rules.mk +include $(topsrcdir)/ipc/chromium/chromium-config.mk + diff --git a/dom/fmradio/ipc/PFMRadio.ipdl b/dom/fmradio/ipc/PFMRadio.ipdl new file mode 100644 index 000000000000..9672cb73b36e --- /dev/null +++ b/dom/fmradio/ipc/PFMRadio.ipdl @@ -0,0 +1,94 @@ +/* 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 "mozilla/HalTypes.h"; + +include protocol PContent; +include protocol PFMRadioRequest; + +using mozilla::hal::FMRadioSeekDirection; + +namespace mozilla { +namespace dom { + +struct EnableRequestArgs +{ + double frequency; +}; + +struct DisableRequestArgs +{ +}; + +struct SetFrequencyRequestArgs +{ + double frequency; +}; + +struct SeekRequestArgs +{ + FMRadioSeekDirection direction; +}; + +struct CancelSeekRequestArgs +{ +}; + +union FMRadioRequestArgs +{ + EnableRequestArgs; + DisableRequestArgs; + SetFrequencyRequestArgs; + SeekRequestArgs; + CancelSeekRequestArgs; +}; + +struct StatusInfo +{ + bool enabled; + double frequency; + double upperBound; + double lowerBound; + double channelWidth; +}; + +sync protocol PFMRadio +{ + manager PContent; + manages PFMRadioRequest; + +child: + /** + * Sent when the frequency is changed. + */ + NotifyFrequencyChanged(double frequency); + /** + * Sent when the power state of FM radio HW is changed. + */ + NotifyEnabledChanged(bool enabled, double frequency); + + __delete__(); + +parent: + /** + * Get the current status infomation of FM radio HW synchronously. + * Sent when the singleton object of FMRadioChild is initialized. + */ + sync GetStatusInfo() returns (StatusInfo info); + + /** + * Send request to parent process to operate the FM radio HW. + * + * We don't have separate Enable/SetFrequency/etc. methods instead here, + * because we can leverage the IPC messaging mechanism to manage the mapping + * of the asynchronous request and the DOMRequest we returned to the caller + * on web content, otherwise, we have to do the mapping stuff manually which + * is more error prone. + */ + PFMRadioRequest(FMRadioRequestArgs requestType); +}; + +} // namespace dom +} // namespace mozilla + diff --git a/dom/fmradio/ipc/PFMRadioRequest.ipdl b/dom/fmradio/ipc/PFMRadioRequest.ipdl new file mode 100644 index 000000000000..4a456b0e8c68 --- /dev/null +++ b/dom/fmradio/ipc/PFMRadioRequest.ipdl @@ -0,0 +1,43 @@ +/* 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 protocol PFMRadio; + +namespace mozilla { +namespace dom { + +struct ErrorResponse +{ + nsString error; +}; + +struct SuccessResponse +{ +}; + +union FMRadioResponseType +{ + ErrorResponse; + SuccessResponse; +}; + +/** + * The protocol is used for sending asynchronous operation requests of + * FM radio HW from child to parent, and the type of the request is defined in + * FMRadioRequestArgs. + * + * When the request completed, the result, i.e. FMRadioResponseType, will be + * sent back to child from parent in the `__delete__` message. + */ +async protocol PFMRadioRequest +{ + manager PFMRadio; + +child: + __delete__(FMRadioResponseType response); +}; + +} // namespace dom +} // namespace mozilla + diff --git a/dom/fmradio/ipc/moz.build b/dom/fmradio/ipc/moz.build new file mode 100644 index 000000000000..06a242f44d0a --- /dev/null +++ b/dom/fmradio/ipc/moz.build @@ -0,0 +1,24 @@ +# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +EXPORTS.mozilla.dom += [ + 'FMRadioChild.h', + 'FMRadioParent.h', + 'FMRadioRequestChild.h', + 'FMRadioRequestParent.h', +] + +CPP_SOURCES += [ + 'FMRadioChild.cpp', + 'FMRadioParent.cpp', + 'FMRadioRequestChild.cpp', + 'FMRadioRequestParent.cpp', +] + +FAIL_ON_WARNINGS = True + +LIBXUL_LIBRARY = True + diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 22fa571bab13..f4ef80570486 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -98,6 +98,7 @@ #include "mozilla/dom/mobilemessage/SmsChild.h" #include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h" #include "mozilla/dom/bluetooth/PBluetoothChild.h" +#include "mozilla/dom/PFMRadioChild.h" #include "mozilla/ipc/InputStreamUtils.h" #ifdef MOZ_WEBSPEECH @@ -925,6 +926,30 @@ ContentChild::DeallocPBluetoothChild(PBluetoothChild* aActor) #endif } +PFMRadioChild* +ContentChild::AllocPFMRadioChild() +{ +#ifdef MOZ_B2G_FM + NS_RUNTIMEABORT("No one should be allocating PFMRadioChild actors"); + return nullptr; +#else + NS_RUNTIMEABORT("No support for FMRadio on this platform!"); + return nullptr; +#endif +} + +bool +ContentChild::DeallocPFMRadioChild(PFMRadioChild* aActor) +{ +#ifdef MOZ_B2G_FM + delete aActor; + return true; +#else + NS_RUNTIMEABORT("No support for FMRadio on this platform!"); + return false; +#endif +} + PSpeechSynthesisChild* ContentChild::AllocPSpeechSynthesisChild() { diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index c27d06371a0b..279af64fb619 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -158,6 +158,9 @@ public: virtual PBluetoothChild* AllocPBluetoothChild(); virtual bool DeallocPBluetoothChild(PBluetoothChild* aActor); + virtual PFMRadioChild* AllocPFMRadioChild(); + virtual bool DeallocPFMRadioChild(PFMRadioChild* aActor); + virtual PSpeechSynthesisChild* AllocPSpeechSynthesisChild(); virtual bool DeallocPSpeechSynthesisChild(PSpeechSynthesisChild* aActor); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 163da9dbde5c..2cb6fa9122fd 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -32,6 +32,7 @@ #include "mozilla/dom/power/PowerManagerService.h" #include "mozilla/dom/DOMStorageIPC.h" #include "mozilla/dom/bluetooth/PBluetoothParent.h" +#include "mozilla/dom/PFMRadioParent.h" #include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h" #include "SmsParent.h" #include "mozilla/Hal.h" @@ -125,6 +126,11 @@ using namespace mozilla::system; #endif #include "JavaScriptParent.h" + +#ifdef MOZ_B2G_FM +#include "mozilla/dom/FMRadioParent.h" +#endif + #include "Crypto.h" #ifdef MOZ_WEBSPEECH @@ -2259,6 +2265,32 @@ ContentParent::RecvPBluetoothConstructor(PBluetoothParent* aActor) #endif } +PFMRadioParent* +ContentParent::AllocPFMRadioParent() +{ +#ifdef MOZ_B2G_FM + if (!AssertAppProcessPermission(this, "fmradio")) { + return nullptr; + } + return new FMRadioParent(); +#else + NS_WARNING("No support for FMRadio on this platform!"); + return nullptr; +#endif +} + +bool +ContentParent::DeallocPFMRadioParent(PFMRadioParent* aActor) +{ +#ifdef MOZ_B2G_FM + delete aActor; + return true; +#else + NS_WARNING("No support for FMRadio on this platform!"); + return false; +#endif +} + PSpeechSynthesisParent* ContentParent::AllocPSpeechSynthesisParent() { diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 0f6759a36201..5bfa77b18d1a 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -328,6 +328,9 @@ private: virtual bool DeallocPBluetoothParent(PBluetoothParent* aActor); virtual bool RecvPBluetoothConstructor(PBluetoothParent* aActor); + virtual PFMRadioParent* AllocPFMRadioParent(); + virtual bool DeallocPFMRadioParent(PFMRadioParent* aActor); + virtual PSpeechSynthesisParent* AllocPSpeechSynthesisParent(); virtual bool DeallocPSpeechSynthesisParent(PSpeechSynthesisParent* aActor); virtual bool RecvPSpeechSynthesisConstructor(PSpeechSynthesisParent* aActor); diff --git a/dom/ipc/Makefile.in b/dom/ipc/Makefile.in index 09108c969912..1253550b987f 100644 --- a/dom/ipc/Makefile.in +++ b/dom/ipc/Makefile.in @@ -33,6 +33,7 @@ LOCAL_INCLUDES += \ -I$(topsrcdir)/hal/sandbox \ -I$(topsrcdir)/dom/mobilemessage/src/ipc \ -I$(topsrcdir)/dom/devicestorage \ + -I$(topsrcdir)/dom/fmradio/ipc \ -I$(topsrcdir)/widget/xpwidgets \ -I$(topsrcdir)/dom/bluetooth \ -I$(topsrcdir)/layout/base \ diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 0054ffb521c1..eb706f624d47 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -11,6 +11,7 @@ include protocol PCompositor; include protocol PCrashReporter; include protocol PExternalHelperApp; include protocol PDeviceStorageRequest; +include protocol PFMRadio; include protocol PHal; include protocol PImageBridge; include protocol PIndexedDB; @@ -126,6 +127,40 @@ union DeviceStorageParams DeviceStorageAvailableParams; }; +struct FMRadioRequestEnableParams +{ + double frequency; +}; + +struct FMRadioRequestDisableParams +{ + +}; + +struct FMRadioRequestSetFrequencyParams +{ + double frequency; +}; + +struct FMRadioRequestSeekParams +{ + bool upward; +}; + +struct FMRadioRequestCancelSeekParams +{ + +}; + +union FMRadioRequestParams +{ + FMRadioRequestEnableParams; + FMRadioRequestDisableParams; + FMRadioRequestSetFrequencyParams; + FMRadioRequestSeekParams; + FMRadioRequestCancelSeekParams; +}; + union PrefValue { nsCString; int32_t; @@ -154,6 +189,7 @@ rpc protocol PContent manages PCrashReporter; manages PDeviceStorageRequest; manages PExternalHelperApp; + manages PFMRadio; manages PHal; manages PIndexedDB; manages PMemoryReportRequest; @@ -319,6 +355,8 @@ parent: PBluetooth(); + PFMRadio(); + // Services remoting async StartVisitedQuery(URIParams uri);