1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef A_MESSAGE_H_ 18 19 #define A_MESSAGE_H_ 20 21 #include <media/stagefright/foundation/ABase.h> 22 #include <media/stagefright/foundation/ALooper.h> 23 #include <utils/KeyedVector.h> 24 #include <utils/RefBase.h> 25 26 namespace android { 27 28 struct AString; 29 30 struct AMessage : public RefBase { 31 AMessage(uint32_t what = 0, ALooper::handler_id target = 0); 32 33 void setWhat(uint32_t what); 34 uint32_t what() const; 35 36 void setTarget(ALooper::handler_id target); 37 ALooper::handler_id target() const; 38 39 void setInt32(const char *name, int32_t value); 40 void setInt64(const char *name, int64_t value); 41 void setSize(const char *name, size_t value); 42 void setFloat(const char *name, float value); 43 void setDouble(const char *name, double value); 44 void setPointer(const char *name, void *value); 45 void setString(const char *name, const char *s, ssize_t len = -1); 46 void setObject(const char *name, const sp<RefBase> &obj); 47 void setMessage(const char *name, const sp<AMessage> &obj); 48 49 bool findInt32(const char *name, int32_t *value) const; 50 bool findInt64(const char *name, int64_t *value) const; 51 bool findSize(const char *name, size_t *value) const; 52 bool findFloat(const char *name, float *value) const; 53 bool findDouble(const char *name, double *value) const; 54 bool findPointer(const char *name, void **value) const; 55 bool findString(const char *name, AString *value) const; 56 bool findObject(const char *name, sp<RefBase> *obj) const; 57 bool findMessage(const char *name, sp<AMessage> *obj) const; 58 59 void post(int64_t delayUs = 0); 60 61 sp<AMessage> dup() const; 62 63 AString debugString(int32_t indent = 0) const; 64 65 protected: 66 virtual ~AMessage(); 67 68 private: 69 enum Type { 70 kTypeInt32, 71 kTypeInt64, 72 kTypeSize, 73 kTypeFloat, 74 kTypeDouble, 75 kTypePointer, 76 kTypeString, 77 kTypeObject, 78 kTypeMessage, 79 }; 80 81 uint32_t mWhat; 82 ALooper::handler_id mTarget; 83 84 struct Item { 85 union { 86 int32_t int32Value; 87 int64_t int64Value; 88 size_t sizeValue; 89 float floatValue; 90 double doubleValue; 91 void *ptrValue; 92 RefBase *refValue; 93 AString *stringValue; 94 } u; 95 const char *mName; 96 Type mType; 97 }; 98 99 enum { 100 kMaxNumItems = 16 101 }; 102 Item mItems[kMaxNumItems]; 103 size_t mNumItems; 104 105 void clear(); 106 Item *allocateItem(const char *name); 107 void freeItem(Item *item); 108 const Item *findItem(const char *name, Type type) const; 109 110 DISALLOW_EVIL_CONSTRUCTORS(AMessage); 111 }; 112 113 } // namespace android 114 115 #endif // A_MESSAGE_H_ 116