AMessage.h revision f933441648ef6a71dee783d733aac17b9508b452
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
6772961230a5890071bcca436eb5630172ce84ec41Andreas Huber    sp<AMessage> dup() const;
6872961230a5890071bcca436eb5630172ce84ec41Andreas Huber
69bbc2b8289458cfde931b133bad0c9d1026674ee7Andreas Huber    AString debugString(int32_t indent = 0) const;
70bbc2b8289458cfde931b133bad0c9d1026674ee7Andreas Huber
7172961230a5890071bcca436eb5630172ce84ec41Andreas Huberprotected:
7272961230a5890071bcca436eb5630172ce84ec41Andreas Huber    virtual ~AMessage();
7372961230a5890071bcca436eb5630172ce84ec41Andreas Huber
7472961230a5890071bcca436eb5630172ce84ec41Andreas Huberprivate:
7572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    enum Type {
7672961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypeInt32,
7772961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypeInt64,
7872961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypeSize,
7972961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypeFloat,
8072961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypeDouble,
8172961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypePointer,
8272961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypeString,
8372961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypeObject,
8472961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kTypeMessage,
8572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    };
8672961230a5890071bcca436eb5630172ce84ec41Andreas Huber
8772961230a5890071bcca436eb5630172ce84ec41Andreas Huber    uint32_t mWhat;
8872961230a5890071bcca436eb5630172ce84ec41Andreas Huber    ALooper::handler_id mTarget;
8972961230a5890071bcca436eb5630172ce84ec41Andreas Huber
9072961230a5890071bcca436eb5630172ce84ec41Andreas Huber    struct Item {
9172961230a5890071bcca436eb5630172ce84ec41Andreas Huber        union {
9272961230a5890071bcca436eb5630172ce84ec41Andreas Huber            int32_t int32Value;
9372961230a5890071bcca436eb5630172ce84ec41Andreas Huber            int64_t int64Value;
9472961230a5890071bcca436eb5630172ce84ec41Andreas Huber            size_t sizeValue;
9572961230a5890071bcca436eb5630172ce84ec41Andreas Huber            float floatValue;
9672961230a5890071bcca436eb5630172ce84ec41Andreas Huber            double doubleValue;
9772961230a5890071bcca436eb5630172ce84ec41Andreas Huber            void *ptrValue;
9872961230a5890071bcca436eb5630172ce84ec41Andreas Huber            RefBase *refValue;
9972961230a5890071bcca436eb5630172ce84ec41Andreas Huber            AString *stringValue;
10072961230a5890071bcca436eb5630172ce84ec41Andreas Huber        } u;
10172961230a5890071bcca436eb5630172ce84ec41Andreas Huber        const char *mName;
10272961230a5890071bcca436eb5630172ce84ec41Andreas Huber        Type mType;
10372961230a5890071bcca436eb5630172ce84ec41Andreas Huber    };
10472961230a5890071bcca436eb5630172ce84ec41Andreas Huber
10572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    enum {
10672961230a5890071bcca436eb5630172ce84ec41Andreas Huber        kMaxNumItems = 16
10772961230a5890071bcca436eb5630172ce84ec41Andreas Huber    };
10872961230a5890071bcca436eb5630172ce84ec41Andreas Huber    Item mItems[kMaxNumItems];
10972961230a5890071bcca436eb5630172ce84ec41Andreas Huber    size_t mNumItems;
11072961230a5890071bcca436eb5630172ce84ec41Andreas Huber
11172961230a5890071bcca436eb5630172ce84ec41Andreas Huber    Item *allocateItem(const char *name);
11272961230a5890071bcca436eb5630172ce84ec41Andreas Huber    void freeItem(Item *item);
11372961230a5890071bcca436eb5630172ce84ec41Andreas Huber    const Item *findItem(const char *name, Type type) const;
11472961230a5890071bcca436eb5630172ce84ec41Andreas Huber
11572961230a5890071bcca436eb5630172ce84ec41Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(AMessage);
11672961230a5890071bcca436eb5630172ce84ec41Andreas Huber};
11772961230a5890071bcca436eb5630172ce84ec41Andreas Huber
11872961230a5890071bcca436eb5630172ce84ec41Andreas Huber}  // namespace android
11972961230a5890071bcca436eb5630172ce84ec41Andreas Huber
12072961230a5890071bcca436eb5630172ce84ec41Andreas Huber#endif  // A_MESSAGE_H_
121