summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorManuel Roman <manuelroman@google.com>2011-10-13 17:21:46 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-13 17:21:46 -0700
commitf2608b71add2665ddb0c5d9a2181f881321c5f89 (patch)
tree196e5663387beba180d2325580c9ed2080ad770c /tools
parent9b43d8e67c9ad52c66f310b6cc5e7fdd6e9bbf02 (diff)
parentc7ec1dc21ae33a976817cc2deefdcb9065c1803b (diff)
downloadframeworks_base-f2608b71add2665ddb0c5d9a2181f881321c5f89.zip
frameworks_base-f2608b71add2665ddb0c5d9a2181f881321c5f89.tar.gz
frameworks_base-f2608b71add2665ddb0c5d9a2181f881321c5f89.tar.bz2
Merge changes I3a51e45a,I73b21022,I6a3984f9 into ics-aah
* changes: Update aidl for new Broker API. aidl: All flattenable types now must also be parcelable. Update aidl to new APIs.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/aidl/Type.cpp62
-rwxr-xr-xtools/aidl/Type.h23
-rw-r--r--tools/aidl/aidl.cpp101
-rw-r--r--tools/aidl/aidl_language.h19
-rw-r--r--tools/aidl/aidl_language_y.y28
-rw-r--r--tools/aidl/generate_java_rpc.cpp164
6 files changed, 177 insertions, 220 deletions
diff --git a/tools/aidl/Type.cpp b/tools/aidl/Type.cpp
index 8161ef3..b84b3c4 100755
--- a/tools/aidl/Type.cpp
+++ b/tools/aidl/Type.cpp
@@ -123,7 +123,7 @@ register_base_types()
RPC_DATA_TYPE = new RpcDataType();
NAMES.Add(RPC_DATA_TYPE);
- RPC_ERROR_TYPE = new ParcelableType("com.android.athome.rpc", "RpcError",
+ RPC_ERROR_TYPE = new UserDataType("com.android.athome.rpc", "RpcError",
true, __FILE__, __LINE__);
NAMES.Add(RPC_ERROR_TYPE);
@@ -896,29 +896,22 @@ ListType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, V
// ================================================================
-ParcelableType::ParcelableType(const string& package, const string& name,
- bool builtIn, const string& declFile, int declLine)
- :Type(package, name, builtIn ? BUILT_IN : PARCELABLE, true, false, true,
- declFile, declLine)
-{
-}
-
-ParcelableType::ParcelableType(const string& package, const string& name,
- bool builtIn, bool canWriteToRpcData,
- const string& declFile, int declLine)
- :Type(package, name, builtIn ? BUILT_IN : PARCELABLE, true, canWriteToRpcData, true,
- declFile, declLine)
+UserDataType::UserDataType(const string& package, const string& name,
+ bool builtIn, bool canWriteToParcel, bool canWriteToRpcData,
+ const string& declFile, int declLine)
+ :Type(package, name, builtIn ? BUILT_IN : USERDATA, canWriteToParcel, canWriteToRpcData,
+ true, declFile, declLine)
{
}
string
-ParcelableType::CreatorName() const
+UserDataType::CreatorName() const
{
return QualifiedName() + ".CREATOR";
}
void
-ParcelableType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags)
+UserDataType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags)
{
// if (v != null) {
// parcel.writeInt(1);
@@ -941,7 +934,7 @@ ParcelableType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parc
}
void
-ParcelableType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**)
+UserDataType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**)
{
// if (0 != parcel.readInt()) {
// v = CLASS.CREATOR.createFromParcel(parcel)
@@ -962,7 +955,7 @@ ParcelableType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* p
}
void
-ParcelableType::ReadFromParcel(StatementBlock* addTo, Variable* v,
+UserDataType::ReadFromParcel(StatementBlock* addTo, Variable* v,
Variable* parcel, Variable**)
{
// TODO: really, we don't need to have this extra check, but we
@@ -978,20 +971,20 @@ ParcelableType::ReadFromParcel(StatementBlock* addTo, Variable* v,
}
bool
-ParcelableType::CanBeArray() const
+UserDataType::CanBeArray() const
{
return true;
}
void
-ParcelableType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags)
+UserDataType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags)
{
addTo->Add(new MethodCall(parcel, "writeTypedArray", 2, v,
BuildWriteToParcelFlags(flags)));
}
void
-ParcelableType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v,
+UserDataType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v,
Variable* parcel, Variable**)
{
string creator = v->type->QualifiedName() + ".CREATOR";
@@ -1000,30 +993,15 @@ ParcelableType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v,
}
void
-ParcelableType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**)
+UserDataType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**)
{
string creator = v->type->QualifiedName() + ".CREATOR";
addTo->Add(new MethodCall(parcel, "readTypedArray", 2,
v, new LiteralExpression(creator)));
}
-// ================================================================
-
-FlattenableType::FlattenableType(const string& package, const string& name,
- bool builtIn, const string& declFile, int declLine)
- :Type(package, name, builtIn ? BUILT_IN : PARCELABLE, false, true, true,
- declFile, declLine)
-{
-}
-
-string
-FlattenableType::CreatorName() const
-{
- return QualifiedName() + ".CREATOR";
-}
-
void
-FlattenableType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v,
+UserDataType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v,
Variable* data, int flags)
{
// if (v != null) {
@@ -1042,7 +1020,7 @@ FlattenableType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable*
}
void
-FlattenableType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v,
+UserDataType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v,
Variable* data, Variable** cl)
{
// RpcData _obj_XX = data.getRpcData(k);
@@ -1070,12 +1048,6 @@ FlattenableType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variabl
block->Add(ifpart);
}
-bool
-FlattenableType::CanBeArray() const
-{
- return true;
-}
-
// ================================================================
InterfaceType::InterfaceType(const string& package, const string& name,
@@ -1266,7 +1238,7 @@ GenericListType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variabl
// ================================================================
RpcDataType::RpcDataType()
- :ParcelableType("com.android.athome.rpc", "RpcData", true, true)
+ :UserDataType("com.android.athome.rpc", "RpcData", true, true, true)
{
}
diff --git a/tools/aidl/Type.h b/tools/aidl/Type.h
index a144448..f2f3f21 100755
--- a/tools/aidl/Type.h
+++ b/tools/aidl/Type.h
@@ -13,7 +13,7 @@ public:
// kinds
enum {
BUILT_IN,
- PARCELABLE,
+ USERDATA,
INTERFACE,
GENERATED
};
@@ -350,13 +350,11 @@ public:
Variable* data, Variable** cl);
};
-class ParcelableType : public Type
+class UserDataType : public Type
{
public:
- ParcelableType(const string& package, const string& name,
- bool builtIn, const string& declFile, int declLine);
- ParcelableType(const string& package, const string& name,
- bool builtIn, bool canWriteToRpcData,
+ UserDataType(const string& package, const string& name,
+ bool builtIn, bool canWriteToParcel, bool canWriteToRpcData,
const string& declFile = "", int declLine = -1);
virtual string CreatorName() const;
@@ -376,22 +374,11 @@ public:
Variable* parcel, Variable** cl);
virtual void ReadArrayFromParcel(StatementBlock* addTo, Variable* v,
Variable* parcel, Variable** cl);
-};
-
-class FlattenableType : public Type
-{
-public:
- FlattenableType(const string& package, const string& name,
- bool builtIn, const string& declFile, int declLine);
-
- virtual string CreatorName() const;
virtual void WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v,
Variable* data, int flags);
virtual void CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v,
Variable* data, Variable** cl);
-
- virtual bool CanBeArray() const;
};
class InterfaceType : public Type
@@ -437,7 +424,7 @@ private:
vector<Type*> m_args;
};
-class RpcDataType : public ParcelableType
+class RpcDataType : public UserDataType
{
public:
RpcDataType();
diff --git a/tools/aidl/aidl.cpp b/tools/aidl/aidl.cpp
index ab9a245..e5689b9 100644
--- a/tools/aidl/aidl.cpp
+++ b/tools/aidl/aidl.cpp
@@ -50,13 +50,14 @@ test_document(document_item_type* d)
}
printf("}\n");
}
- else if (d->item_type == PARCELABLE_TYPE) {
- parcelable_type* b = (parcelable_type*)d;
- printf("parcelable %s %s;\n", b->package, b->name.data);
- }
- else if (d->item_type == FLATTENABLE_TYPE) {
- parcelable_type* b = (parcelable_type*)d;
- printf("flattenable %s %s;\n", b->package, b->name.data);
+ else if (d->item_type == USER_DATA_TYPE) {
+ user_data_type* b = (user_data_type*)d;
+ if ((b->flattening_methods & PARCELABLE_DATA) != 0) {
+ printf("parcelable %s %s;\n", b->package, b->name.data);
+ }
+ if ((b->flattening_methods & RPC_DATA) != 0) {
+ printf("flattenable %s %s;\n", b->package, b->name.data);
+ }
}
else {
printf("UNKNOWN d=0x%08lx d->item_type=%d\n", (long)d, d->item_type);
@@ -242,9 +243,8 @@ check_filenames(const char* filename, document_item_type* items)
{
int err = 0;
while (items) {
- if (items->item_type == PARCELABLE_TYPE
- || items->item_type == FLATTENABLE_TYPE) {
- parcelable_type* p = (parcelable_type*)items;
+ if (items->item_type == USER_DATA_TYPE) {
+ user_data_type* p = (user_data_type*)items;
err |= check_filename(filename, p->package, &p->name);
}
else if (items->item_type == INTERFACE_TYPE_BINDER
@@ -270,8 +270,8 @@ kind_to_string(int kind)
{
case Type::INTERFACE:
return "an interface";
- case Type::PARCELABLE:
- return "a parcelable";
+ case Type::USERDATA:
+ return "a user data";
default:
return "ERROR";
}
@@ -296,15 +296,11 @@ gather_types(const char* filename, document_item_type* items)
int err = 0;
while (items) {
Type* type;
- if (items->item_type == PARCELABLE_TYPE) {
- parcelable_type* p = (parcelable_type*)items;
- type = new ParcelableType(p->package ? p->package : "",
- p->name.data, false, filename, p->name.lineno);
- }
- else if (items->item_type == FLATTENABLE_TYPE) {
- parcelable_type* p = (parcelable_type*)items;
- type = new FlattenableType(p->package ? p->package : "",
- p->name.data, false, filename, p->name.lineno);
+ if (items->item_type == USER_DATA_TYPE) {
+ user_data_type* p = (user_data_type*)items;
+ type = new UserDataType(p->package ? p->package : "", p->name.data,
+ false, ((p->flattening_methods & PARCELABLE_DATA) != 0),
+ ((p->flattening_methods & RPC_DATA) != 0), filename, p->name.lineno);
}
else if (items->item_type == INTERFACE_TYPE_BINDER
|| items->item_type == INTERFACE_TYPE_RPC) {
@@ -539,7 +535,7 @@ check_types(const char* filename, document_item_type* items)
{
int err = 0;
while (items) {
- // (nothing to check for PARCELABLE_TYPE or FLATTENABLE_TYPE)
+ // (nothing to check for USER_DATA_TYPE)
if (items->item_type == INTERFACE_TYPE_BINDER
|| items->item_type == INTERFACE_TYPE_RPC) {
map<string,method_type*> methodNames;
@@ -593,26 +589,23 @@ exactly_one_interface(const char* filename, const document_item_type* items, con
else if (next->item_type == INTERFACE_TYPE_RPC) {
lineno = ((interface_type*)next)->interface_token.lineno;
}
- else if (next->item_type == PARCELABLE_TYPE) {
- lineno = ((parcelable_type*)next)->parcelable_token.lineno;
- }
- else if (next->item_type == FLATTENABLE_TYPE) {
- lineno = ((parcelable_type*)next)->parcelable_token.lineno;
+ else if (next->item_type == USER_DATA_TYPE) {
+ lineno = ((user_data_type*)next)->keyword_token.lineno;
}
fprintf(stderr, "%s:%d aidl can only handle one interface per file\n",
filename, lineno);
return 1;
}
- if (items->item_type == PARCELABLE_TYPE || items->item_type == FLATTENABLE_TYPE) {
+ if (items->item_type == USER_DATA_TYPE) {
*onlyParcelable = true;
if (options.failOnParcelable) {
fprintf(stderr, "%s:%d aidl can only generate code for interfaces, not"
" parcelables or flattenables,\n", filename,
- ((parcelable_type*)items)->parcelable_token.lineno);
+ ((user_data_type*)items)->keyword_token.lineno);
fprintf(stderr, "%s:%d .aidl files that only declare parcelables or flattenables"
"may not go in the Makefile.\n", filename,
- ((parcelable_type*)items)->parcelable_token.lineno);
+ ((user_data_type*)items)->keyword_token.lineno);
return 1;
}
} else {
@@ -711,8 +704,8 @@ generate_outputFileName(const Options& options, const document_item_type* items)
interface_type* type = (interface_type*)items;
return generate_outputFileName2(options, type->name, type->package);
- } else if (items->item_type == PARCELABLE_TYPE || items->item_type == FLATTENABLE_TYPE) {
- parcelable_type* type = (parcelable_type*)items;
+ } else if (items->item_type == USER_DATA_TYPE) {
+ user_data_type* type = (user_data_type*)items;
return generate_outputFileName2(options, type->name, type->package);
}
@@ -783,31 +776,33 @@ parse_preprocessed_file(const string& filename)
document_item_type* doc;
if (0 == strcmp("parcelable", type)) {
- parcelable_type* parcl = (parcelable_type*)malloc(
- sizeof(parcelable_type));
- memset(parcl, 0, sizeof(parcelable_type));
- parcl->document_item.item_type = PARCELABLE_TYPE;
- parcl->parcelable_token.lineno = lineno;
- parcl->parcelable_token.data = strdup(type);
+ user_data_type* parcl = (user_data_type*)malloc(
+ sizeof(user_data_type));
+ memset(parcl, 0, sizeof(user_data_type));
+ parcl->document_item.item_type = USER_DATA_TYPE;
+ parcl->keyword_token.lineno = lineno;
+ parcl->keyword_token.data = strdup(type);
parcl->package = packagename ? strdup(packagename) : NULL;
parcl->name.lineno = lineno;
parcl->name.data = strdup(classname);
parcl->semicolon_token.lineno = lineno;
parcl->semicolon_token.data = strdup(";");
+ parcl->flattening_methods = PARCELABLE_DATA;
doc = (document_item_type*)parcl;
}
else if (0 == strcmp("flattenable", type)) {
- parcelable_type* parcl = (parcelable_type*)malloc(
- sizeof(parcelable_type));
- memset(parcl, 0, sizeof(parcelable_type));
- parcl->document_item.item_type = FLATTENABLE_TYPE;
- parcl->parcelable_token.lineno = lineno;
- parcl->parcelable_token.data = strdup(type);
+ user_data_type* parcl = (user_data_type*)malloc(
+ sizeof(user_data_type));
+ memset(parcl, 0, sizeof(user_data_type));
+ parcl->document_item.item_type = USER_DATA_TYPE;
+ parcl->keyword_token.lineno = lineno;
+ parcl->keyword_token.data = strdup(type);
parcl->package = packagename ? strdup(packagename) : NULL;
parcl->name.lineno = lineno;
parcl->name.data = strdup(classname);
parcl->semicolon_token.lineno = lineno;
parcl->semicolon_token.data = strdup(";");
+ parcl->flattening_methods = RPC_DATA;
doc = (document_item_type*)parcl;
}
else if (0 == strcmp("interface", type)) {
@@ -986,18 +981,14 @@ preprocess_aidl(const Options& options)
}
document_item_type* doc = g_document;
string line;
- if (doc->item_type == PARCELABLE_TYPE) {
- line = "parcelable ";
- parcelable_type* parcelable = (parcelable_type*)doc;
- if (parcelable->package) {
- line += parcelable->package;
- line += '.';
+ if (doc->item_type == USER_DATA_TYPE) {
+ user_data_type* parcelable = (user_data_type*)doc;
+ if ((parcelable->flattening_methods & PARCELABLE_DATA) != 0) {
+ line = "parcelable ";
+ }
+ if ((parcelable->flattening_methods & RPC_DATA) != 0) {
+ line = "flattenable ";
}
- line += parcelable->name.data;
- }
- else if (doc->item_type == FLATTENABLE_TYPE) {
- line = "parcelable ";
- parcelable_type* parcelable = (parcelable_type*)doc;
if (parcelable->package) {
line += parcelable->package;
line += '.';
diff --git a/tools/aidl/aidl_language.h b/tools/aidl/aidl_language.h
index b490a59..f203dbb 100644
--- a/tools/aidl/aidl_language.h
+++ b/tools/aidl/aidl_language.h
@@ -63,8 +63,7 @@ typedef struct method_type {
} method_type;
enum {
- PARCELABLE_TYPE = 12,
- FLATTENABLE_TYPE,
+ USER_DATA_TYPE = 12,
INTERFACE_TYPE_BINDER,
INTERFACE_TYPE_RPC
};
@@ -74,13 +73,21 @@ typedef struct document_item_type {
struct document_item_type* next;
} document_item_type;
-typedef struct parcelable_type {
+
+// for user_data_type.flattening_methods
+enum {
+ PARCELABLE_DATA = 0x1,
+ RPC_DATA = 0x2
+};
+
+typedef struct user_data_type {
document_item_type document_item;
- buffer_type parcelable_token;
+ buffer_type keyword_token; // only the first one
char* package;
buffer_type name;
buffer_type semicolon_token;
-} parcelable_type;
+ int flattening_methods;
+} user_data_type;
typedef struct interface_type {
document_item_type document_item;
@@ -102,7 +109,7 @@ typedef union lexer_type {
method_type* method;
interface_item_type* interface_item;
interface_type* interface_obj;
- parcelable_type* parcelable;
+ user_data_type* user_data;
document_item_type* document_item;
} lexer_type;
diff --git a/tools/aidl/aidl_language_y.y b/tools/aidl/aidl_language_y.y
index 12bb3d7..cc04d15 100644
--- a/tools/aidl/aidl_language_y.y
+++ b/tools/aidl/aidl_language_y.y
@@ -74,50 +74,52 @@ document_items:
;
declaration:
- parcelable_decl { $$.document_item = (document_item_type*)$1.parcelable; }
+ parcelable_decl { $$.document_item = (document_item_type*)$1.user_data; }
| interface_decl { $$.document_item = (document_item_type*)$1.interface_item; }
;
parcelable_decl:
PARCELABLE IDENTIFIER ';' {
- parcelable_type* b = (parcelable_type*)malloc(sizeof(parcelable_type));
- b->document_item.item_type = PARCELABLE_TYPE;
+ user_data_type* b = (user_data_type*)malloc(sizeof(user_data_type));
+ b->document_item.item_type = USER_DATA_TYPE;
b->document_item.next = NULL;
- b->parcelable_token = $1.buffer;
+ b->keyword_token = $1.buffer;
b->name = $2.buffer;
b->package = g_currentPackage ? strdup(g_currentPackage) : NULL;
b->semicolon_token = $3.buffer;
- $$.parcelable = b;
+ b->flattening_methods = PARCELABLE_DATA;
+ $$.user_data = b;
}
| PARCELABLE ';' {
fprintf(stderr, "%s:%d syntax error in parcelable declaration. Expected type name.\n",
g_currentFilename, $1.buffer.lineno);
- $$.parcelable = NULL;
+ $$.user_data = NULL;
}
| PARCELABLE error ';' {
fprintf(stderr, "%s:%d syntax error in parcelable declaration. Expected type name, saw \"%s\".\n",
g_currentFilename, $2.buffer.lineno, $2.buffer.data);
- $$.parcelable = NULL;
+ $$.user_data = NULL;
}
| FLATTENABLE IDENTIFIER ';' {
- parcelable_type* b = (parcelable_type*)malloc(sizeof(parcelable_type));
- b->document_item.item_type = FLATTENABLE_TYPE;
+ user_data_type* b = (user_data_type*)malloc(sizeof(user_data_type));
+ b->document_item.item_type = USER_DATA_TYPE;
b->document_item.next = NULL;
- b->parcelable_token = $1.buffer;
+ b->keyword_token = $1.buffer;
b->name = $2.buffer;
b->package = g_currentPackage ? strdup(g_currentPackage) : NULL;
b->semicolon_token = $3.buffer;
- $$.parcelable = b;
+ b->flattening_methods = PARCELABLE_DATA | RPC_DATA;
+ $$.user_data = b;
}
| FLATTENABLE ';' {
fprintf(stderr, "%s:%d syntax error in flattenable declaration. Expected type name.\n",
g_currentFilename, $1.buffer.lineno);
- $$.parcelable = NULL;
+ $$.user_data = NULL;
}
| FLATTENABLE error ';' {
fprintf(stderr, "%s:%d syntax error in flattenable declaration. Expected type name, saw \"%s\".\n",
g_currentFilename, $2.buffer.lineno, $2.buffer.data);
- $$.parcelable = NULL;
+ $$.user_data = NULL;
}
;
diff --git a/tools/aidl/generate_java_rpc.cpp b/tools/aidl/generate_java_rpc.cpp
index 8353c45..e4867e4 100644
--- a/tools/aidl/generate_java_rpc.cpp
+++ b/tools/aidl/generate_java_rpc.cpp
@@ -7,21 +7,24 @@
Type* SERVICE_CONTEXT_TYPE = new Type("android.content",
"Context", Type::BUILT_IN, false, false, false);
-Type* PRESENTER_BASE_TYPE = new Type("com.android.athome.service",
- "AndroidAtHomePresenter", Type::BUILT_IN, false, false, false);
-Type* PRESENTER_LISTENER_BASE_TYPE = new Type("com.android.athome.service",
- "AndroidAtHomePresenter.Listener", Type::BUILT_IN, false, false, false);
-Type* RPC_BROKER_TYPE = new Type("com.android.athome.utils", "AndroidAtHomeBroker",
+Type* PRESENTER_BASE_TYPE = new Type("com.android.athome.connector",
+ "EventListener", Type::BUILT_IN, false, false, false);
+Type* PRESENTER_LISTENER_BASE_TYPE = new Type("com.android.athome.connector",
+ "EventListener.Listener", Type::BUILT_IN, false, false, false);
+Type* RPC_BROKER_TYPE = new Type("com.android.athome.connector", "Broker",
Type::BUILT_IN, false, false, false);
-Type* RPC_SERVICE_BASE_TYPE = new Type("com.android.athome.service", "AndroidAtHomeService",
+Type* RPC_CONTAINER_TYPE = new Type("com.android.athome.connector", "ConnectorContainer",
Type::BUILT_IN, false, false, false);
-Type* RPC_SERVICE_INFO_TYPE = new ParcelableType("com.android.athome.stubs",
- "AndroidAtHomeServiceInfo", true, __FILE__, __LINE__);
-Type* RPC_RESULT_HANDLER_TYPE = new ParcelableType("com.android.athome.rpc", "RpcResultHandler",
+// TODO: Just use Endpoint, so this works for all endpoints.
+Type* RPC_CONNECTOR_TYPE = new Type("com.android.athome.connector", "Connector",
+ Type::BUILT_IN, false, false, false);
+Type* RPC_ENDPOINT_INFO_TYPE = new UserDataType("com.android.athome.rpc",
+ "EndpointInfo", true, __FILE__, __LINE__);
+Type* RPC_RESULT_HANDLER_TYPE = new UserDataType("com.android.athome.rpc", "RpcResultHandler",
true, __FILE__, __LINE__);
Type* RPC_ERROR_LISTENER_TYPE = new Type("com.android.athome.rpc", "RpcErrorHandler",
Type::BUILT_IN, false, false, false);
-Type* RPC_CONTEXT_TYPE = new ParcelableType("com.android.athome.rpc", "RpcContext", true,
+Type* RPC_CONTEXT_TYPE = new UserDataType("com.android.athome.rpc", "RpcContext", true,
__FILE__, __LINE__);
static void generate_create_from_data(Type* t, StatementBlock* addTo, const string& key,
@@ -286,7 +289,7 @@ public:
virtual ~RpcProxyClass();
Variable* endpoint;
- Variable* context;
+ Variable* broker;
private:
void generate_ctor();
@@ -300,11 +303,11 @@ RpcProxyClass::RpcProxyClass(const interface_type* iface, InterfaceType* interfa
this->what = Class::CLASS;
this->type = interfaceType;
- // context
- this->context = new Variable(CONTEXT_TYPE, "_context");
- this->elements.push_back(new Field(PRIVATE, this->context));
+ // broker
+ this->broker = new Variable(RPC_BROKER_TYPE, "_broker");
+ this->elements.push_back(new Field(PRIVATE, this->broker));
// endpoint
- this->endpoint = new Variable(RPC_SERVICE_INFO_TYPE, "_endpoint");
+ this->endpoint = new Variable(RPC_ENDPOINT_INFO_TYPE, "_endpoint");
this->elements.push_back(new Field(PRIVATE, this->endpoint));
// methods
@@ -318,26 +321,26 @@ RpcProxyClass::~RpcProxyClass()
void
RpcProxyClass::generate_ctor()
{
- Variable* context = new Variable(CONTEXT_TYPE, "context");
- Variable* endpoint = new Variable(RPC_SERVICE_INFO_TYPE, "endpoint");
+ Variable* broker = new Variable(RPC_BROKER_TYPE, "broker");
+ Variable* endpoint = new Variable(RPC_ENDPOINT_INFO_TYPE, "endpoint");
Method* ctor = new Method;
ctor->modifiers = PUBLIC;
ctor->name = class_name_leaf(this->type->Name());
ctor->statements = new StatementBlock;
- ctor->parameters.push_back(context);
+ ctor->parameters.push_back(broker);
ctor->parameters.push_back(endpoint);
this->elements.push_back(ctor);
- ctor->statements->Add(new Assignment(this->context, context));
+ ctor->statements->Add(new Assignment(this->broker, broker));
ctor->statements->Add(new Assignment(this->endpoint, endpoint));
}
// =================================================
-class PresenterClass : public DispatcherClass
+class EventListenerClass : public DispatcherClass
{
public:
- PresenterClass(const interface_type* iface, Type* listenerType);
- virtual ~PresenterClass();
+ EventListenerClass(const interface_type* iface, Type* listenerType);
+ virtual ~EventListenerClass();
Variable* _listener;
@@ -351,8 +354,8 @@ generate_get_listener_expression(Type* cast)
return new Cast(cast, new MethodCall(THIS_VALUE, "getView"));
}
-PresenterClass::PresenterClass(const interface_type* iface, Type* listenerType)
- :DispatcherClass(iface, generate_get_listener_expression(listenerType))
+EventListenerClass::EventListenerClass(const interface_type* iface, Type* listenerType)
+ :DispatcherClass(iface, new FieldVariable(THIS_VALUE, "_listener"))
{
this->modifiers = PRIVATE;
this->what = Class::CLASS;
@@ -368,26 +371,24 @@ PresenterClass::PresenterClass(const interface_type* iface, Type* listenerType)
generate_ctor();
}
-PresenterClass::~PresenterClass()
+EventListenerClass::~EventListenerClass()
{
}
void
-PresenterClass::generate_ctor()
+EventListenerClass::generate_ctor()
{
- Variable* context = new Variable(CONTEXT_TYPE, "context");
- Variable* endpoint = new Variable(RPC_SERVICE_INFO_TYPE, "endpoint");
+ Variable* broker = new Variable(RPC_BROKER_TYPE, "broker");
Variable* listener = new Variable(this->_listener->type, "listener");
Method* ctor = new Method;
ctor->modifiers = PUBLIC;
ctor->name = class_name_leaf(this->type->Name());
ctor->statements = new StatementBlock;
- ctor->parameters.push_back(context);
- ctor->parameters.push_back(endpoint);
+ ctor->parameters.push_back(broker);
ctor->parameters.push_back(listener);
this->elements.push_back(ctor);
- ctor->statements->Add(new MethodCall("super", 3, context, endpoint, listener));
+ ctor->statements->Add(new MethodCall("super", 2, broker, listener));
ctor->statements->Add(new Assignment(this->_listener, listener));
}
@@ -422,11 +423,11 @@ ListenerClass::~ListenerClass()
}
// =================================================
-class ServiceBaseClass : public DispatcherClass
+class EndpointBaseClass : public DispatcherClass
{
public:
- ServiceBaseClass(const interface_type* iface);
- virtual ~ServiceBaseClass();
+ EndpointBaseClass(const interface_type* iface);
+ virtual ~EndpointBaseClass();
bool needed;
@@ -434,7 +435,7 @@ private:
void generate_ctor();
};
-ServiceBaseClass::ServiceBaseClass(const interface_type* iface)
+EndpointBaseClass::EndpointBaseClass(const interface_type* iface)
:DispatcherClass(iface, THIS_VALUE),
needed(false)
{
@@ -442,36 +443,32 @@ ServiceBaseClass::ServiceBaseClass(const interface_type* iface)
this->modifiers = STATIC | PUBLIC | ABSTRACT;
this->what = Class::CLASS;
this->type = new Type(iface->package ? iface->package : "",
- append(iface->name.data, ".ServiceBase"),
+ append(iface->name.data, ".EndpointBase"),
Type::GENERATED, false, false, false);
- this->extends = RPC_SERVICE_BASE_TYPE;
+ this->extends = RPC_CONNECTOR_TYPE;
// methods
generate_ctor();
}
-ServiceBaseClass::~ServiceBaseClass()
+EndpointBaseClass::~EndpointBaseClass()
{
}
void
-ServiceBaseClass::generate_ctor()
+EndpointBaseClass::generate_ctor()
{
- Variable* context = new Variable(SERVICE_CONTEXT_TYPE, "context");
- Variable* name = new Variable(STRING_TYPE, "name");
- Variable* type = new Variable(STRING_TYPE, "type");
- Variable* version = new Variable(INT_TYPE, "version");
+ Variable* container = new Variable(RPC_CONTAINER_TYPE, "container");
+ Variable* broker = new Variable(RPC_BROKER_TYPE, "broker");
Method* ctor = new Method;
ctor->modifiers = PUBLIC;
ctor->name = class_name_leaf(this->type->Name());
ctor->statements = new StatementBlock;
- ctor->parameters.push_back(context);
- ctor->parameters.push_back(name);
- ctor->parameters.push_back(type);
- ctor->parameters.push_back(version);
+ ctor->parameters.push_back(container);
+ ctor->parameters.push_back(broker);
this->elements.push_back(ctor);
- ctor->statements->Add(new MethodCall("super", 4, context, name, type, version));
+ ctor->statements->Add(new MethodCall("super", 2, container, broker));
}
// =================================================
@@ -711,10 +708,10 @@ generate_proxy_method(const method_type* method, RpcProxyClass* proxyClass,
proxyMethod->parameters.push_back(errorListener);
// Call the broker
- proxyMethod->statements->Add(new MethodCall(RPC_BROKER_TYPE, "sendRequest", 6,
- new FieldVariable(THIS_VALUE, "_context"),
- new StringLiteralExpression(method->name.data),
+ proxyMethod->statements->Add(new MethodCall(new FieldVariable(THIS_VALUE, "_broker"),
+ "sendRpc", 5,
proxyClass->endpoint,
+ new StringLiteralExpression(method->name.data),
new MethodCall(_data, "serialize"),
resultParameter,
errorListener));
@@ -773,7 +770,7 @@ generate_result_dispatcher_method(const method_type* method,
static void
generate_regular_method(const method_type* method, RpcProxyClass* proxyClass,
- ServiceBaseClass* serviceBaseClass, ResultDispatcherClass* resultsDispatcherClass,
+ EndpointBaseClass* serviceBaseClass, ResultDispatcherClass* resultsDispatcherClass,
int index)
{
arg_type* arg;
@@ -818,8 +815,8 @@ generate_regular_method(const method_type* method, RpcProxyClass* proxyClass,
static void
generate_event_method(const method_type* method, RpcProxyClass* proxyClass,
- ServiceBaseClass* serviceBaseClass, ListenerClass* listenerClass,
- PresenterClass* presenterClass, int index)
+ EndpointBaseClass* serviceBaseClass, ListenerClass* listenerClass,
+ EventListenerClass* presenterClass, int index)
{
arg_type* arg;
listenerClass->needed = true;
@@ -883,14 +880,14 @@ static void
generate_listener_methods(RpcProxyClass* proxyClass, Type* presenterType, Type* listenerType)
{
// AndroidAtHomePresenter _presenter;
- // void registerListener(Listener listener) {
- // unregisterListener();
- // _presenter = new Presenter(_context, _endpoint, listener);
- // _presenter.attachToModel();
+ // void startListening(Listener listener) {
+ // stopListening();
+ // _presenter = new Presenter(_broker, listener);
+ // _presenter.startListening(_endpoint);
// }
- // void unregisterListener() {
+ // void stopListening() {
// if (_presenter != null) {
- // _presenter.detachFromModel();
+ // _presenter.stopListening();
// }
// }
@@ -899,31 +896,32 @@ generate_listener_methods(RpcProxyClass* proxyClass, Type* presenterType, Type*
Variable* listener = new Variable(listenerType, "listener");
- Method* registerMethod = new Method;
- registerMethod->modifiers = PUBLIC;
- registerMethod->returnType = VOID_TYPE;
- registerMethod->name = "registerListener";
- registerMethod->statements = new StatementBlock;
- registerMethod->parameters.push_back(listener);
- proxyClass->elements.push_back(registerMethod);
-
- registerMethod->statements->Add(new MethodCall(THIS_VALUE, "unregisterListener"));
- registerMethod->statements->Add(new Assignment(_presenter, new NewExpression(presenterType,
- 3, proxyClass->context, proxyClass->endpoint, listener)));
- registerMethod->statements->Add(new MethodCall(_presenter, "attachToModel"));
-
- Method* unregisterMethod = new Method;
- unregisterMethod->modifiers = PUBLIC;
- unregisterMethod->returnType = VOID_TYPE;
- unregisterMethod->name = "unregisterListener";
- unregisterMethod->statements = new StatementBlock;
- proxyClass->elements.push_back(unregisterMethod);
+ Method* startListeningMethod = new Method;
+ startListeningMethod->modifiers = PUBLIC;
+ startListeningMethod->returnType = VOID_TYPE;
+ startListeningMethod->name = "startListening";
+ startListeningMethod->statements = new StatementBlock;
+ startListeningMethod->parameters.push_back(listener);
+ proxyClass->elements.push_back(startListeningMethod);
+
+ startListeningMethod->statements->Add(new MethodCall(THIS_VALUE, "stopListening"));
+ startListeningMethod->statements->Add(new Assignment(_presenter,
+ new NewExpression(presenterType, 2, proxyClass->broker, listener)));
+ startListeningMethod->statements->Add(new MethodCall(_presenter,
+ "startListening", 1, proxyClass->endpoint));
+
+ Method* stopListeningMethod = new Method;
+ stopListeningMethod->modifiers = PUBLIC;
+ stopListeningMethod->returnType = VOID_TYPE;
+ stopListeningMethod->name = "stopListening";
+ stopListeningMethod->statements = new StatementBlock;
+ proxyClass->elements.push_back(stopListeningMethod);
IfStatement* ifst = new IfStatement;
ifst->expression = new Comparison(_presenter, "!=", NULL_VALUE);
- unregisterMethod->statements->Add(ifst);
+ stopListeningMethod->statements->Add(ifst);
- ifst->statements->Add(new MethodCall(_presenter, "detachFromModel"));
+ ifst->statements->Add(new MethodCall(_presenter, "stopListening"));
ifst->statements->Add(new Assignment(_presenter, NULL_VALUE));
}
@@ -939,10 +937,10 @@ generate_rpc_interface_class(const interface_type* iface)
ListenerClass* listener = new ListenerClass(iface);
// the presenter class
- PresenterClass* presenter = new PresenterClass(iface, listener->type);
+ EventListenerClass* presenter = new EventListenerClass(iface, listener->type);
// the service base class
- ServiceBaseClass* base = new ServiceBaseClass(iface);
+ EndpointBaseClass* base = new EndpointBaseClass(iface);
proxy->elements.push_back(base);
// the result dispatcher