AMessage.h revision 2c2814b900a61fa07ddfff860b143fbbe9c740e9
172961230a5890071bcca436eb5630172ce84ec41Andreas Huber/* 272961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Copyright (C) 2010 The Android Open Source Project 372961230a5890071bcca436eb5630172ce84ec41Andreas Huber * 472961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 572961230a5890071bcca436eb5630172ce84ec41Andreas Huber * you may not use this file except in compliance with the License. 672961230a5890071bcca436eb5630172ce84ec41Andreas Huber * You may obtain a copy of the License at 772961230a5890071bcca436eb5630172ce84ec41Andreas Huber * 872961230a5890071bcca436eb5630172ce84ec41Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 972961230a5890071bcca436eb5630172ce84ec41Andreas Huber * 1072961230a5890071bcca436eb5630172ce84ec41Andreas Huber * Unless required by applicable law or agreed to in writing, software 1172961230a5890071bcca436eb5630172ce84ec41Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 1272961230a5890071bcca436eb5630172ce84ec41Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1372961230a5890071bcca436eb5630172ce84ec41Andreas Huber * See the License for the specific language governing permissions and 1472961230a5890071bcca436eb5630172ce84ec41Andreas Huber * limitations under the License. 1572961230a5890071bcca436eb5630172ce84ec41Andreas Huber */ 1672961230a5890071bcca436eb5630172ce84ec41Andreas Huber 1772961230a5890071bcca436eb5630172ce84ec41Andreas Huber#ifndef A_MESSAGE_H_ 1872961230a5890071bcca436eb5630172ce84ec41Andreas Huber 1972961230a5890071bcca436eb5630172ce84ec41Andreas Huber#define A_MESSAGE_H_ 2072961230a5890071bcca436eb5630172ce84ec41Andreas Huber 2172961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <media/stagefright/foundation/ABase.h> 2272961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <media/stagefright/foundation/ALooper.h> 2372961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <utils/KeyedVector.h> 2472961230a5890071bcca436eb5630172ce84ec41Andreas Huber#include <utils/RefBase.h> 2572961230a5890071bcca436eb5630172ce84ec41Andreas Huber 2672961230a5890071bcca436eb5630172ce84ec41Andreas Hubernamespace android { 2772961230a5890071bcca436eb5630172ce84ec41Andreas Huber 2872961230a5890071bcca436eb5630172ce84ec41Andreas Huberstruct AString; 2914acc736e336cbd6026df781d4f411e908831815Andreas Huberstruct Parcel; 3072961230a5890071bcca436eb5630172ce84ec41Andreas Huber 3172961230a5890071bcca436eb5630172ce84ec41Andreas Huberstruct AMessage : public RefBase { 3272961230a5890071bcca436eb5630172ce84ec41Andreas Huber AMessage(uint32_t what = 0, ALooper::handler_id target = 0); 3372961230a5890071bcca436eb5630172ce84ec41Andreas Huber 3414acc736e336cbd6026df781d4f411e908831815Andreas Huber static sp<AMessage> FromParcel(const Parcel &parcel); 3514acc736e336cbd6026df781d4f411e908831815Andreas Huber void writeToParcel(Parcel *parcel) const; 3614acc736e336cbd6026df781d4f411e908831815Andreas Huber 3772961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setWhat(uint32_t what); 3872961230a5890071bcca436eb5630172ce84ec41Andreas Huber uint32_t what() const; 3972961230a5890071bcca436eb5630172ce84ec41Andreas Huber 4072961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setTarget(ALooper::handler_id target); 4172961230a5890071bcca436eb5630172ce84ec41Andreas Huber ALooper::handler_id target() const; 4272961230a5890071bcca436eb5630172ce84ec41Andreas Huber 43f933441648ef6a71dee783d733aac17b9508b452Andreas Huber void clear(); 44f933441648ef6a71dee783d733aac17b9508b452Andreas Huber 4572961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setInt32(const char *name, int32_t value); 4672961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setInt64(const char *name, int64_t value); 4772961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setSize(const char *name, size_t value); 4872961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setFloat(const char *name, float value); 4972961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setDouble(const char *name, double value); 5072961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setPointer(const char *name, void *value); 5172961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setString(const char *name, const char *s, ssize_t len = -1); 5272961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setObject(const char *name, const sp<RefBase> &obj); 5372961230a5890071bcca436eb5630172ce84ec41Andreas Huber void setMessage(const char *name, const sp<AMessage> &obj); 5472961230a5890071bcca436eb5630172ce84ec41Andreas Huber 5572961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findInt32(const char *name, int32_t *value) const; 5672961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findInt64(const char *name, int64_t *value) const; 5772961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findSize(const char *name, size_t *value) const; 5872961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findFloat(const char *name, float *value) const; 5972961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findDouble(const char *name, double *value) const; 6072961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findPointer(const char *name, void **value) const; 6172961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findString(const char *name, AString *value) const; 6272961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findObject(const char *name, sp<RefBase> *obj) const; 6372961230a5890071bcca436eb5630172ce84ec41Andreas Huber bool findMessage(const char *name, sp<AMessage> *obj) const; 6472961230a5890071bcca436eb5630172ce84ec41Andreas Huber 6572961230a5890071bcca436eb5630172ce84ec41Andreas Huber void post(int64_t delayUs = 0); 6672961230a5890071bcca436eb5630172ce84ec41Andreas Huber 672c2814b900a61fa07ddfff860b143fbbe9c740e9Andreas Huber // Performs a deep-copy of "this", contained messages are in turn "dup'ed". 682c2814b900a61fa07ddfff860b143fbbe9c740e9Andreas Huber // Warning: RefBase items, i.e. "objects" are _not_ copied but only have 692c2814b900a61fa07ddfff860b143fbbe9c740e9Andreas Huber // their refcount incremented. 7072961230a5890071bcca436eb5630172ce84ec41Andreas Huber sp<AMessage> dup() const; 7172961230a5890071bcca436eb5630172ce84ec41Andreas Huber 72bbc2b8289458cfde931b133bad0c9d1026674ee7Andreas Huber AString debugString(int32_t indent = 0) const; 73bbc2b8289458cfde931b133bad0c9d1026674ee7Andreas Huber 7472961230a5890071bcca436eb5630172ce84ec41Andreas Huberprotected: 7572961230a5890071bcca436eb5630172ce84ec41Andreas Huber virtual ~AMessage(); 7672961230a5890071bcca436eb5630172ce84ec41Andreas Huber 7772961230a5890071bcca436eb5630172ce84ec41Andreas Huberprivate: 7872961230a5890071bcca436eb5630172ce84ec41Andreas Huber enum Type { 7972961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypeInt32, 8072961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypeInt64, 8172961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypeSize, 8272961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypeFloat, 8372961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypeDouble, 8472961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypePointer, 8572961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypeString, 8672961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypeObject, 8772961230a5890071bcca436eb5630172ce84ec41Andreas Huber kTypeMessage, 8872961230a5890071bcca436eb5630172ce84ec41Andreas Huber }; 8972961230a5890071bcca436eb5630172ce84ec41Andreas Huber 9072961230a5890071bcca436eb5630172ce84ec41Andreas Huber uint32_t mWhat; 9172961230a5890071bcca436eb5630172ce84ec41Andreas Huber ALooper::handler_id mTarget; 9272961230a5890071bcca436eb5630172ce84ec41Andreas Huber 9372961230a5890071bcca436eb5630172ce84ec41Andreas Huber struct Item { 9472961230a5890071bcca436eb5630172ce84ec41Andreas Huber union { 9572961230a5890071bcca436eb5630172ce84ec41Andreas Huber int32_t int32Value; 9672961230a5890071bcca436eb5630172ce84ec41Andreas Huber int64_t int64Value; 9772961230a5890071bcca436eb5630172ce84ec41Andreas Huber size_t sizeValue; 9872961230a5890071bcca436eb5630172ce84ec41Andreas Huber float floatValue; 9972961230a5890071bcca436eb5630172ce84ec41Andreas Huber double doubleValue; 10072961230a5890071bcca436eb5630172ce84ec41Andreas Huber void *ptrValue; 10172961230a5890071bcca436eb5630172ce84ec41Andreas Huber RefBase *refValue; 10272961230a5890071bcca436eb5630172ce84ec41Andreas Huber AString *stringValue; 10372961230a5890071bcca436eb5630172ce84ec41Andreas Huber } u; 10472961230a5890071bcca436eb5630172ce84ec41Andreas Huber const char *mName; 10572961230a5890071bcca436eb5630172ce84ec41Andreas Huber Type mType; 10672961230a5890071bcca436eb5630172ce84ec41Andreas Huber }; 10772961230a5890071bcca436eb5630172ce84ec41Andreas Huber 10872961230a5890071bcca436eb5630172ce84ec41Andreas Huber enum { 10972961230a5890071bcca436eb5630172ce84ec41Andreas Huber kMaxNumItems = 16 11072961230a5890071bcca436eb5630172ce84ec41Andreas Huber }; 11172961230a5890071bcca436eb5630172ce84ec41Andreas Huber Item mItems[kMaxNumItems]; 11272961230a5890071bcca436eb5630172ce84ec41Andreas Huber size_t mNumItems; 11372961230a5890071bcca436eb5630172ce84ec41Andreas Huber 11472961230a5890071bcca436eb5630172ce84ec41Andreas Huber Item *allocateItem(const char *name); 11572961230a5890071bcca436eb5630172ce84ec41Andreas Huber void freeItem(Item *item); 11672961230a5890071bcca436eb5630172ce84ec41Andreas Huber const Item *findItem(const char *name, Type type) const; 11772961230a5890071bcca436eb5630172ce84ec41Andreas Huber 11872961230a5890071bcca436eb5630172ce84ec41Andreas Huber DISALLOW_EVIL_CONSTRUCTORS(AMessage); 11972961230a5890071bcca436eb5630172ce84ec41Andreas Huber}; 12072961230a5890071bcca436eb5630172ce84ec41Andreas Huber 12172961230a5890071bcca436eb5630172ce84ec41Andreas Huber} // namespace android 12272961230a5890071bcca436eb5630172ce84ec41Andreas Huber 12372961230a5890071bcca436eb5630172ce84ec41Andreas Huber#endif // A_MESSAGE_H_ 124