зеркало из https://github.com/mozilla/pjs.git
Bug 674725 - Part N - Receiving SMS: IPC handling. r=cjones
This commit is contained in:
Родитель
bc8297a45c
Коммит
799eb9e97f
|
@ -62,7 +62,8 @@ EXPORTS_mozilla/dom/sms = \
|
|||
SmsChild.h \
|
||||
SmsParent.h \
|
||||
SmsServiceFactory.h \
|
||||
Constants.h
|
||||
Constants.h \
|
||||
Types.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
@ -74,6 +75,7 @@ CPPSRCS = \
|
|||
SmsMessage.cpp \
|
||||
SmsEvent.cpp \
|
||||
Constants.cpp \
|
||||
SmsChild.cpp \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "SmsMessage.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec
|
||||
#include "Constants.h"
|
||||
|
||||
DOMCI_DATA(MozSmsMessage, mozilla::dom::sms::SmsMessage)
|
||||
|
||||
|
@ -54,35 +55,38 @@ NS_INTERFACE_MAP_END
|
|||
NS_IMPL_ADDREF(SmsMessage)
|
||||
NS_IMPL_RELEASE(SmsMessage)
|
||||
|
||||
SmsMessage::SmsMessage(PRInt32 aId, DeliveryState aDelivery,
|
||||
const nsAString& aSender, const nsAString& aReceiver,
|
||||
const nsAString& aBody, PRUint64 aTimestamp)
|
||||
: mId(aId)
|
||||
, mDelivery(aDelivery)
|
||||
, mSender(aSender)
|
||||
, mReceiver(aReceiver)
|
||||
, mBody(aBody)
|
||||
, mTimestamp(aTimestamp)
|
||||
SmsMessage::SmsMessage(const SmsMessageData& aData)
|
||||
: mData(aData)
|
||||
{
|
||||
}
|
||||
|
||||
const SmsMessageData&
|
||||
SmsMessage::GetData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessage::GetId(PRInt32* aId)
|
||||
{
|
||||
*aId = mId;
|
||||
*aId = mData.id();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessage::GetDelivery(nsAString& aDelivery)
|
||||
{
|
||||
switch (mDelivery) {
|
||||
case eDeliveryState_Sent:
|
||||
aDelivery.AssignLiteral("sent");
|
||||
break;
|
||||
switch (mData.delivery()) {
|
||||
case eDeliveryState_Received:
|
||||
aDelivery.AssignLiteral("received");
|
||||
break;
|
||||
case eDeliveryState_Sent:
|
||||
aDelivery.AssignLiteral("sent");
|
||||
break;
|
||||
case eDeliveryState_Unknown:
|
||||
default:
|
||||
NS_ASSERTION(true, "We shouldn't get an unknown delivery state!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -91,28 +95,28 @@ SmsMessage::GetDelivery(nsAString& aDelivery)
|
|||
NS_IMETHODIMP
|
||||
SmsMessage::GetSender(nsAString& aSender)
|
||||
{
|
||||
aSender = mSender;
|
||||
aSender = mData.sender();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessage::GetReceiver(nsAString& aReceiver)
|
||||
{
|
||||
aReceiver = mReceiver;
|
||||
aReceiver = mData.receiver();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessage::GetBody(nsAString& aBody)
|
||||
{
|
||||
aBody = mBody;
|
||||
aBody = mData.body();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessage::GetTimestamp(JSContext* cx, jsval* aDate)
|
||||
{
|
||||
*aDate = OBJECT_TO_JSVAL(JS_NewDateObjectMsec(cx, mTimestamp));
|
||||
*aDate = OBJECT_TO_JSVAL(JS_NewDateObjectMsec(cx, mData.timestamp()));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#ifndef mozilla_dom_sms_SmsMessage_h
|
||||
#define mozilla_dom_sms_SmsMessage_h
|
||||
|
||||
#include "mozilla/dom/sms/PSms.h"
|
||||
#include "nsIDOMSmsMessage.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
@ -48,28 +49,18 @@ namespace sms {
|
|||
class SmsMessage : public nsIDOMMozSmsMessage
|
||||
{
|
||||
public:
|
||||
enum DeliveryState {
|
||||
eDeliveryState_Sent,
|
||||
eDeliveryState_Received
|
||||
};
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMMOZSMSMESSAGE
|
||||
|
||||
SmsMessage(PRInt32 aId, DeliveryState aDelivery, const nsAString& aSender,
|
||||
const nsAString& aReceiver, const nsAString& aBody,
|
||||
PRUint64 aTimestamp);
|
||||
SmsMessage(const SmsMessageData& aData);
|
||||
|
||||
const SmsMessageData& GetData() const;
|
||||
|
||||
private:
|
||||
// Don't try to use the default constructor.
|
||||
SmsMessage();
|
||||
|
||||
PRInt32 mId;
|
||||
DeliveryState mDelivery;
|
||||
nsString mSender;
|
||||
nsString mReceiver;
|
||||
nsString mBody;
|
||||
PRUint64 mTimestamp; // Milliseconds to epoch.
|
||||
SmsMessageData mData;
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef mozilla_dom_sms_Types_h
|
||||
#define mozilla_dom_sms_Types_h
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace sms {
|
||||
|
||||
// For SmsMessageDate.delivery.
|
||||
enum DeliveryState {
|
||||
eDeliveryState_Sent,
|
||||
eDeliveryState_Received,
|
||||
// This state should stay at the end.
|
||||
eDeliveryState_Unknown
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
namespace IPC {
|
||||
|
||||
/**
|
||||
* Delivery state serializer.
|
||||
*/
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::sms::DeliveryState>
|
||||
: public EnumSerializer<mozilla::dom::sms::DeliveryState,
|
||||
mozilla::dom::sms::eDeliveryState_Sent,
|
||||
mozilla::dom::sms::eDeliveryState_Unknown>
|
||||
{};
|
||||
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_dom_sms_Types_h
|
|
@ -38,14 +38,29 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
include protocol PContent;
|
||||
include "mozilla/dom/sms/Types.h";
|
||||
|
||||
using DeliveryState;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace sms {
|
||||
|
||||
struct SmsMessageData {
|
||||
PRInt32 id;
|
||||
DeliveryState delivery;
|
||||
nsString sender;
|
||||
nsString receiver;
|
||||
nsString body;
|
||||
PRUint64 timestamp; // ms since epoch.
|
||||
};
|
||||
|
||||
sync protocol PSms {
|
||||
manager PContent;
|
||||
|
||||
child:
|
||||
NotifyReceivedMessage(SmsMessageData aMessageData);
|
||||
|
||||
parent:
|
||||
sync HasSupport()
|
||||
returns (bool aHasSupport);
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "SmsChild.h"
|
||||
#include "SmsMessage.h"
|
||||
#include "Constants.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace sms {
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyReceivedMessage(const SmsMessageData& aMessageData)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<SmsMessage> message = new SmsMessage(aMessageData);
|
||||
obs->NotifyObservers(message, kSmsReceivedObserverTopic, nsnull);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -46,6 +46,8 @@ namespace sms {
|
|||
|
||||
class SmsChild : public PSmsChild
|
||||
{
|
||||
public:
|
||||
NS_OVERRIDE virtual bool RecvNotifyReceivedMessage(const SmsMessageData& aMessage);
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
|
|
|
@ -37,11 +37,58 @@
|
|||
|
||||
#include "SmsParent.h"
|
||||
#include "nsISmsService.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "Constants.h"
|
||||
#include "nsIDOMSmsMessage.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "SmsMessage.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace sms {
|
||||
|
||||
NS_IMPL_ISUPPORTS1(SmsParent, nsIObserver)
|
||||
|
||||
SmsParent::SmsParent()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
}
|
||||
|
||||
obs->AddObserver(this, kSmsReceivedObserverTopic, false);
|
||||
}
|
||||
|
||||
void
|
||||
SmsParent::ActorDestroy(ActorDestroyReason why)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
}
|
||||
|
||||
obs->RemoveObserver(this, kSmsReceivedObserverTopic);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsParent::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const PRUnichar* aData)
|
||||
{
|
||||
if (!strcmp(aTopic, kSmsReceivedObserverTopic)) {
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
|
||||
if (!message) {
|
||||
NS_ERROR("Got a 'sms-received' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
unused << SendNotifyReceivedMessage(static_cast<SmsMessage*>(message.get())->GetData());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvHasSupport(bool* aHasSupport)
|
||||
{
|
||||
|
|
|
@ -39,16 +39,27 @@
|
|||
#define mozilla_dom_sms_SmsParent_h
|
||||
|
||||
#include "mozilla/dom/sms/PSmsParent.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace sms {
|
||||
|
||||
class SmsParent : public PSmsParent
|
||||
, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
SmsParent();
|
||||
|
||||
NS_OVERRIDE virtual bool RecvHasSupport(bool* aHasSupport);
|
||||
NS_OVERRIDE virtual bool RecvGetNumberOfMessagesForText(const nsString& aText, PRUint16* aResult);
|
||||
NS_OVERRIDE virtual bool RecvSendMessage(const nsString& aNumber, const nsString& aMessage);
|
||||
|
||||
protected:
|
||||
virtual void ActorDestroy(ActorDestroyReason why);
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
|
|
|
@ -96,6 +96,37 @@ struct null_t {
|
|||
|
||||
namespace IPC {
|
||||
|
||||
/**
|
||||
* Generic enum serializer.
|
||||
* E is the enum type.
|
||||
* lowBound is the lowest allowed value of the enum.
|
||||
* highBound is the value higher than highest allowed value of the enum.
|
||||
* In other words, it's the lowest unallowed value.
|
||||
*/
|
||||
template <typename E, E lowBound, E highBound>
|
||||
struct EnumSerializer {
|
||||
typedef E paramType;
|
||||
|
||||
static bool IsLegalValue(const paramType &aValue) {
|
||||
return lowBound <= aValue && aValue < highBound;
|
||||
}
|
||||
|
||||
static void Write(Message* aMsg, const paramType& aValue) {
|
||||
MOZ_ASSERT(IsLegalValue(aValue));
|
||||
WriteParam(aMsg, (int32)aValue);
|
||||
}
|
||||
|
||||
static bool Read(const Message* aMsg, void** aIter, paramType* aResult) {
|
||||
int32 value;
|
||||
if(!ReadParam(aMsg, aIter, &value) ||
|
||||
!IsLegalValue(paramType(value))) {
|
||||
return false;
|
||||
}
|
||||
*aResult = paramType(value);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ParamTraits<PRInt8>
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче