diff options
author | Joe Onorato <joeo@google.com> | 2011-09-02 15:28:36 -0700 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-10-28 10:14:49 -0400 |
commit | 1f44bba3b68ab4a6e45955847d6010285bb74923 (patch) | |
tree | 82b72985cadebf2a4f20d2e31028f2c80eb3ecdd | |
parent | ae7f32e97d2ee62af7ee904849b0dd7a665ae28a (diff) | |
download | frameworks_base-1f44bba3b68ab4a6e45955847d6010285bb74923.zip frameworks_base-1f44bba3b68ab4a6e45955847d6010285bb74923.tar.gz frameworks_base-1f44bba3b68ab4a6e45955847d6010285bb74923.tar.bz2 |
Add the full suite of RpcData types.
Change-Id: I0ce17d46b21cbfe04ff7bd77dd71be70dc7f80ac
-rwxr-xr-x | tools/aidl/AST.cpp | 14 | ||||
-rwxr-xr-x | tools/aidl/AST.h | 7 | ||||
-rwxr-xr-x | tools/aidl/Type.cpp | 159 | ||||
-rwxr-xr-x | tools/aidl/Type.h | 60 | ||||
-rw-r--r-- | tools/aidl/generate_java_rpc.cpp | 19 |
5 files changed, 204 insertions, 55 deletions
diff --git a/tools/aidl/AST.cpp b/tools/aidl/AST.cpp index 42102f8..bfa6765 100755 --- a/tools/aidl/AST.cpp +++ b/tools/aidl/AST.cpp @@ -680,6 +680,20 @@ SwitchStatement::Write(FILE* to) fprintf(to, "}\n"); } +Break::Break() +{ +} + +Break::~Break() +{ +} + +void +Break::Write(FILE* to) +{ + fprintf(to, "break;\n"); +} + Method::Method() :ClassElement(), modifiers(0), diff --git a/tools/aidl/AST.h b/tools/aidl/AST.h index fe92a26..bb090e0 100755 --- a/tools/aidl/AST.h +++ b/tools/aidl/AST.h @@ -307,6 +307,13 @@ struct SwitchStatement : public Statement virtual void Write(FILE* to); }; +struct Break : public Statement +{ + Break(); + virtual ~Break(); + virtual void Write(FILE* to); +}; + struct Method : public ClassElement { string comment; diff --git a/tools/aidl/Type.cpp b/tools/aidl/Type.cpp index 54690e7..4ae4d8b 100755 --- a/tools/aidl/Type.cpp +++ b/tools/aidl/Type.cpp @@ -43,33 +43,40 @@ Expression* FALSE_VALUE; void register_base_types() { - VOID_TYPE = new BasicType("void", "XXX", "XXX", "XXX", "XXX", "XXX"); + VOID_TYPE = new BasicType("void", + "XXX", "XXX", "XXX", "XXX", "XXX", + "XXX", "XXX", "XXX", "XXX", "XXX"); NAMES.Add(VOID_TYPE); BOOLEAN_TYPE = new BooleanType(); NAMES.Add(BOOLEAN_TYPE); - BYTE_TYPE = new BasicType("byte", "writeByte", "readByte", - "writeByteArray", "createByteArray", "readByteArray"); + BYTE_TYPE = new BasicType("byte", + "writeByte", "readByte", "writeByteArray", "createByteArray", "readByteArray", + "putByte", "getByte", "putByteArray", "createByteArray", "getByteArray"); NAMES.Add(BYTE_TYPE); CHAR_TYPE = new CharType(); NAMES.Add(CHAR_TYPE); - INT_TYPE = new BasicType("int", "writeInt", "readInt", - "writeIntArray", "createIntArray", "readIntArray"); + INT_TYPE = new BasicType("int", + "writeInt", "readInt", "writeIntArray", "createIntArray", "readIntArray", + "putInteger", "getInteger", "putIntegerArray", "createIntegerArray", "getIntegerArray"); NAMES.Add(INT_TYPE); - LONG_TYPE = new BasicType("long", "writeLong", "readLong", - "writeLongArray", "createLongArray", "readLongArray"); + LONG_TYPE = new BasicType("long", + "writeLong", "readLong", "writeLongArray", "createLongArray", "readLongArray", + "putLong", "getLong", "putLongArray", "createLongArray", "getLongArray"); NAMES.Add(LONG_TYPE); - FLOAT_TYPE = new BasicType("float", "writeFloat", "readFloat", - "writeFloatArray", "createFloatArray", "readFloatArray"); + FLOAT_TYPE = new BasicType("float", + "writeFloat", "readFloat", "writeFloatArray", "createFloatArray", "readFloatArray", + "putFloat", "getFloat", "putFloatArray", "createFloatArray", "getFloatArray"); NAMES.Add(FLOAT_TYPE); - DOUBLE_TYPE = new BasicType("double", "writeDouble", "readDouble", - "writeDoubleArray", "createDoubleArray", "readDoubleArray"); + DOUBLE_TYPE = new BasicType("double", + "writeDouble", "readDouble", "writeDoubleArray", "createDoubleArray", "readDoubleArray", + "putDouble", "getDouble", "putDoubleArray", "createDoubleArray", "getDoubleArray"); NAMES.Add(DOUBLE_TYPE); STRING_TYPE = new StringType(); @@ -88,8 +95,7 @@ register_base_types() LIST_TYPE = new ListType(); NAMES.Add(LIST_TYPE); - TEXT_UTILS_TYPE = new Type("android.text", "TextUtils", - Type::BUILT_IN, false, false); + TEXT_UTILS_TYPE = new Type("android.text", "TextUtils", Type::BUILT_IN, false, false); NAMES.Add(TEXT_UTILS_TYPE); REMOTE_EXCEPTION_TYPE = new RemoteExceptionType(); @@ -292,27 +298,17 @@ void Type::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, int flags) { - fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%sn", + fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", __FILE__, __LINE__, m_qualifiedName.c_str()); addTo->Add(new LiteralExpression("/* WriteToRpcData error " + m_qualifiedName + " */")); } void -Type::ReadFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, - Variable** cl) -{ - fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%sn", - __FILE__, __LINE__, m_qualifiedName.c_str()); - addTo->Add(new LiteralExpression("/* ReadFromRpcData error " - + m_qualifiedName + " */")); -} - -void Type::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, Variable** cl) { - fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%sn", + fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", __FILE__, __LINE__, m_qualifiedName.c_str()); addTo->Add(new LiteralExpression("/* ReadFromRpcData error " + m_qualifiedName + " */")); @@ -339,29 +335,35 @@ Type::BuildWriteToParcelFlags(int flags) // ================================================================ -BasicType::BasicType(const string& name, const string& marshallMethod, - const string& unmarshallMethod, - const string& writeArray, const string& createArray, - const string& readArray) +BasicType::BasicType(const string& name, const string& marshallParcel, + const string& unmarshallParcel, const string& writeArrayParcel, + const string& createArrayParcel, const string& readArrayParcel, + const string& marshallRpc, const string& unmarshallRpc, + const string& writeArrayRpc, const string& createArrayRpc, const string& readArrayRpc) :Type(name, BUILT_IN, true, false), - m_marshallMethod(marshallMethod), - m_unmarshallMethod(unmarshallMethod), - m_writeArrayMethod(writeArray), - m_createArrayMethod(createArray), - m_readArrayMethod(readArray) + m_marshallParcel(marshallParcel), + m_unmarshallParcel(unmarshallParcel), + m_writeArrayParcel(writeArrayParcel), + m_createArrayParcel(createArrayParcel), + m_readArrayParcel(readArrayParcel), + m_marshallRpc(marshallRpc), + m_unmarshallRpc(unmarshallRpc), + m_writeArrayRpc(writeArrayRpc), + m_createArrayRpc(createArrayRpc), + m_readArrayRpc(readArrayRpc) { } void BasicType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) { - addTo->Add(new MethodCall(parcel, m_marshallMethod, 1, v)); + addTo->Add(new MethodCall(parcel, m_marshallParcel, 1, v)); } void BasicType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) { - addTo->Add(new Assignment(v, new MethodCall(parcel, m_unmarshallMethod))); + addTo->Add(new Assignment(v, new MethodCall(parcel, m_unmarshallParcel))); } bool @@ -373,22 +375,35 @@ BasicType::CanBeArray() const void BasicType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) { - addTo->Add(new MethodCall(parcel, m_writeArrayMethod, 1, v)); + addTo->Add(new MethodCall(parcel, m_writeArrayParcel, 1, v)); } void BasicType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) { - addTo->Add(new Assignment(v, new MethodCall(parcel, m_createArrayMethod))); + addTo->Add(new Assignment(v, new MethodCall(parcel, m_createArrayParcel))); } void BasicType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) { - addTo->Add(new MethodCall(parcel, m_readArrayMethod, 1, v)); + addTo->Add(new MethodCall(parcel, m_readArrayParcel, 1, v)); +} + +void +BasicType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, + Variable* data, int flags) +{ + addTo->Add(new MethodCall(data, m_marshallRpc, 2, k, v)); } +void +BasicType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, + Variable** cl) +{ + addTo->Add(new Assignment(v, new MethodCall(data, m_unmarshallRpc, 1, k))); +} // ================================================================ @@ -437,6 +452,19 @@ BooleanType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* p addTo->Add(new MethodCall(parcel, "readBooleanArray", 1, v)); } +void +BooleanType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, + Variable* data, int flags) +{ + addTo->Add(new MethodCall(data, "putBoolean", 2, k, v)); +} + +void +BooleanType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, + Variable** cl) +{ + addTo->Add(new Assignment(v, new MethodCall(data, "getBoolean", 1, k))); +} // ================================================================ @@ -483,6 +511,20 @@ CharType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parc addTo->Add(new MethodCall(parcel, "readCharArray", 1, v)); } +void +CharType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, + Variable* data, int flags) +{ + addTo->Add(new MethodCall(data, "putChar", 2, k, v)); +} + +void +CharType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, + Variable** cl) +{ + addTo->Add(new Assignment(v, new MethodCall(data, "getChar", 1, k))); +} + // ================================================================ StringType::StringType() @@ -818,8 +860,7 @@ MapType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, } void -MapType::ReadFromParcel(StatementBlock* addTo, Variable* v, - Variable* parcel, Variable** cl) +MapType::ReadFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl) { EnsureClassLoader(addTo, cl); addTo->Add(new MethodCall(parcel, "readMap", 2, v, *cl)); @@ -860,6 +901,19 @@ ListType::ReadFromParcel(StatementBlock* addTo, Variable* v, addTo->Add(new MethodCall(parcel, "readList", 2, v, *cl)); } +void +ListType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, + Variable* data, int flags) +{ + addTo->Add(new MethodCall(data, "putList", 2, k, v)); +} + +void +ListType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, + Variable** cl) +{ + addTo->Add(new Assignment(v, new MethodCall(data, "getList", 1, k))); +} // ================================================================ @@ -1031,6 +1085,12 @@ GenericType::GenericType(const string& package, const string& name, SetQualifiedName(m_importName + gen); } +const vector<Type*>& +GenericType::GenericArgumentTypes() const +{ + return m_args; +} + string GenericType::GenericArguments() const { @@ -1130,6 +1190,23 @@ GenericListType::ReadFromParcel(StatementBlock* addTo, Variable* v, } } +void +GenericListType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, + Variable* data, int flags) +{ + addTo->Add(new MethodCall(data, "putList", 2, k, v)); +} + +void +GenericListType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, + Variable* data, Variable** cl) +{ + string classArg = GenericArgumentTypes()[0]->QualifiedName(); + classArg += ".class"; + addTo->Add(new Assignment(v, new MethodCall(data, "getList", 2, k, + new LiteralExpression(classArg)))); +} + // ================================================================ ClassLoaderType::ClassLoaderType() diff --git a/tools/aidl/Type.h b/tools/aidl/Type.h index 1015dcf..c22ef75 100755 --- a/tools/aidl/Type.h +++ b/tools/aidl/Type.h @@ -63,9 +63,6 @@ public: Variable* data, int flags); virtual void CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, Variable** cl); - virtual void ReadFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, - Variable* data, Variable** cl); - protected: void SetQualifiedName(const string& qualified); @@ -88,11 +85,17 @@ private: class BasicType : public Type { public: - BasicType(const string& name, const string& marshallMethod, - const string& unmarshallMethod, - const string& writeArray, - const string& createArray, - const string& readArray); + BasicType(const string& name, + const string& marshallParcel, + const string& unmarshallParcel, + const string& writeArrayParcel, + const string& createArrayParcel, + const string& readArrayParcel, + const string& marshallRpc, + const string& unmarshallRpc, + const string& writeArrayRpc, + const string& createArrayRpc, + const string& readArrayRpc); virtual void WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags); @@ -108,12 +111,22 @@ public: virtual void ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl); + 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); + private: - string m_marshallMethod; - string m_unmarshallMethod; - string m_writeArrayMethod; - string m_createArrayMethod; - string m_readArrayMethod; + string m_marshallParcel; + string m_unmarshallParcel; + string m_writeArrayParcel; + string m_createArrayParcel; + string m_readArrayParcel; + string m_marshallRpc; + string m_unmarshallRpc; + string m_writeArrayRpc; + string m_createArrayRpc; + string m_readArrayRpc; }; class BooleanType : public Type @@ -134,6 +147,11 @@ public: Variable* parcel, Variable** cl); virtual void ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl); + + 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); }; class CharType : public Type @@ -154,6 +172,11 @@ public: Variable* parcel, Variable** cl); virtual void ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl); + + 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); }; @@ -318,6 +341,11 @@ public: Variable* parcel, Variable** cl); virtual void ReadFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl); + + 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); }; class ParcelableType : public Type @@ -370,6 +398,7 @@ public: GenericType(const string& package, const string& name, const vector<Type*>& args); + const vector<Type*>& GenericArgumentTypes() const; string GenericArguments() const; virtual string ImportType() const; @@ -404,6 +433,11 @@ public: virtual void ReadFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl); + 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); + private: string m_creator; }; diff --git a/tools/aidl/generate_java_rpc.cpp b/tools/aidl/generate_java_rpc.cpp index f7489b3..456a950 100644 --- a/tools/aidl/generate_java_rpc.cpp +++ b/tools/aidl/generate_java_rpc.cpp @@ -169,7 +169,7 @@ ServiceBaseClass::generate_process() this->processMethod->statements->Add(new VariableDeclaration(requestData, new NewExpression(RPC_DATA_TYPE, 1, requestParam))); - this->resultData = new Variable(RPC_DATA_TYPE, "response"); + this->resultData = new Variable(RPC_DATA_TYPE, "resultData"); this->processMethod->statements->Add(new VariableDeclaration(this->resultData, NULL_VALUE)); } @@ -299,6 +299,7 @@ ResultDispatcherClass::AddMethod(int index, const string& name, Method** method, Case* c = new Case(format_int(index)); c->statements->Add(new MethodCall(new LiteralExpression("this"), name, 1, this->resultParam)); + c->statements->Add(new Break()); this->methodSwitch->cases.push_back(c); } @@ -579,6 +580,7 @@ generate_service_base_methods(const method_type* method, ServiceBaseClass* servi } // the real call + bool first = true; Variable* _result = NULL; if (0 == strcmp(method->type.type.data, "void")) { block->Add(realCall); @@ -587,6 +589,13 @@ generate_service_base_methods(const method_type* method, ServiceBaseClass* servi decl->returnTypeDimension); block->Add(new VariableDeclaration(_result, realCall)); + // need the result RpcData + if (first) { + block->Add(new Assignment(serviceBaseClass->resultData, + new NewExpression(RPC_DATA_TYPE))); + first = false; + } + // marshall the return value generate_write_to_data(decl->returnType, block, new StringLiteralExpression("_result"), _result, serviceBaseClass->resultData); @@ -600,6 +609,14 @@ generate_service_base_methods(const method_type* method, ServiceBaseClass* servi Variable* v = stubArgs.Get(i++); if (convert_direction(arg->direction.data) & OUT_PARAMETER) { + // need the result RpcData + if (first) { + block->Add(new Assignment(serviceBaseClass->resultData, + new NewExpression(RPC_DATA_TYPE))); + first = false; + } + + generate_write_to_data(t, block, new StringLiteralExpression(arg->name.data), v, serviceBaseClass->resultData); } |