2009-11-06 12:43:39 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sw=4 et tw=80:
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
#ifndef mozilla_jsipc_ContextWrapperTypes_h__
|
|
|
|
#define mozilla_jsipc_ContextWrapperTypes_h__
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jspubtd.h"
|
|
|
|
|
2010-05-25 00:51:33 -07:00
|
|
|
using mozilla::void_t;
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace jsipc {
|
|
|
|
|
|
|
|
|
|
|
|
template <typename P>
|
|
|
|
struct CPOWSingleton
|
|
|
|
{
|
2012-11-10 07:46:01 -08:00
|
|
|
static void Write(IPC::Message*, const P&) {}
|
|
|
|
static bool Read(const IPC::Message*, void**, P*) { return true; }
|
2009-11-06 12:43:39 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Type, typename As>
|
|
|
|
struct CPOWConvertible
|
|
|
|
{
|
2012-11-10 07:46:01 -08:00
|
|
|
static void Write(IPC::Message* m, const Type& t) {
|
2009-11-06 12:43:39 -08:00
|
|
|
WriteParam(m, As(t));
|
|
|
|
}
|
2012-11-10 07:46:01 -08:00
|
|
|
static bool Read(const IPC::Message* m, void** iter, Type* tp) {
|
2009-11-06 12:43:39 -08:00
|
|
|
As a;
|
|
|
|
return (ReadParam(m, iter, &a) &&
|
|
|
|
(*tp = Type(a), true));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace jsipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
|
2012-11-10 07:46:01 -08:00
|
|
|
template <> struct ParamTraits<JSType> : public mozilla::jsipc::CPOWConvertible<JSType, int> {};
|
2009-11-06 12:43:39 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Use a more standard logging mechanism.
|
|
|
|
#ifdef LOGGING
|
|
|
|
#define CPOW_LOG(PRINTF_ARGS) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
printf("CPOW | "); \
|
|
|
|
printf PRINTF_ARGS ; \
|
|
|
|
printf("\n"); \
|
|
|
|
JS_END_MACRO
|
|
|
|
#define JSVAL_TO_CSTR(CX, V) \
|
|
|
|
NS_ConvertUTF16toUTF8(nsString(JS_GetStringChars(JS_ValueToString(CX, V)))).get()
|
|
|
|
#else
|
|
|
|
#define CPOW_LOG(_) JS_BEGIN_MACRO JS_END_MACRO
|
|
|
|
#define JSVAL_TO_CSTR(CX, V) ((char*)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|