Home | History | Annotate | Download | only in task
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * 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, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 
     18 #ifndef CTSAUDIO_TASKCASE_H
     19 #define CTSAUDIO_TASKCASE_H
     20 
     21 #include <stdint.h>
     22 #include <map>
     23 #include <list>
     24 #include <utility>
     25 #include <utils/String8.h>
     26 #include <utils/StrongPointer.h>
     27 #include "Log.h"
     28 #include "audio/Buffer.h"
     29 #include "TaskGeneric.h"
     30 
     31 class RemoteAudio;
     32 class ClientInterface;
     33 
     34 class TaskCase: public TaskGeneric {
     35 public:
     36     TaskCase();
     37     virtual ~TaskCase();
     38     virtual bool addChild(TaskGeneric* child);
     39     virtual TaskGeneric::ExecutionResult run();
     40 
     41     bool getCaseName(android::String8& name) const;
     42 
     43     bool registerBuffer(const android::String8& name, android::sp<Buffer>& buffer);
     44     // update already existing buffer. Actually the old buffer will be deleted.
     45     bool updateBuffer(const android::String8& name, android::sp<Buffer>& buffer);
     46     /// find buffer with given id. sp will be NULL if not found
     47     android::sp<Buffer> findBuffer(const android::String8& name);
     48     typedef std::pair<android::String8, android::sp<Buffer> > BufferPair;
     49     /// find all buffers with given regular expression. returns NULL if not found
     50     std::list<BufferPair>*  findAllBuffers(const android::String8& re);
     51 
     52     android::sp<RemoteAudio>& getRemoteAudio();
     53 
     54     class Value {
     55     public:
     56         enum Type {
     57             ETypeDouble,
     58             ETypeI64
     59         };
     60         inline Value(): mType(ETypeDouble) {};
     61         inline Value(Type type): mType(type) {};
     62         inline Value(double val): mType(ETypeDouble) {
     63             setDouble(val);
     64         };
     65         inline Value(int64_t val): mType(ETypeI64) {
     66             setInt64(val);
     67         };
     68         inline Type getType() {
     69             return mType;
     70         };
     71         inline void setType(Type type) {
     72             mType = type;
     73         };
     74         inline void setDouble(double val) {
     75             mValue[0] = val;
     76             mType = ETypeDouble;
     77             //LOGD("Value set %f 0x%x", val, this);
     78         };
     79         inline double getDouble() {
     80             //LOGD("Value get %f 0x%x", mValue[0], this);
     81             return mValue[0];
     82         };
     83         inline void setInt64(int64_t val) {
     84             int64_t* data = reinterpret_cast<int64_t*>(mValue);
     85             data[0] = val;
     86             mType = ETypeI64;
     87             //LOGD("Value set %lld 0x%x", val, this);
     88         }
     89         inline int64_t getInt64() {
     90             int64_t* data = reinterpret_cast<int64_t*>(mValue);
     91             //LOGD("Value get %lld 0x%x", data[0], this);
     92             return data[0];
     93         }
     94         void* getPtr() {
     95             return mValue;
     96         }
     97         bool operator ==(const Value& b) const {
     98             return ((mValue[0] == b.mValue[0]) && (mType == b.mType));
     99         };
    100 
    101     private:
    102         double mValue[1];
    103         Type mType;
    104     };
    105 
    106     bool registerValue(const android::String8& name, Value& val);
    107     bool updateValue(const android::String8& name, Value& val);
    108     bool findValue(const android::String8& name, Value& val);
    109     typedef std::pair<android::String8, Value> ValuePair;
    110     /// find all Values with given regular expression. returns NULL if not found
    111     std::list<ValuePair>*  findAllValues(const android::String8& re);
    112 
    113     bool registerIndex(const android::String8& name, int value = -1);
    114     bool updateIndex(const android::String8& name, int value);
    115     bool findIndex(const android::String8& name, int& val);
    116     typedef std::pair<android::String8, int> IndexPair;
    117     /// find all Indices with given regular expression. returns NULL if not found
    118     std::list<IndexPair>*  findAllIndices(const android::String8& re);
    119 
    120     /**
    121      * Translate variable name like $i into index variable
    122      * All xxxValue and xxxBuffer calls do translation inside.
    123      */
    124     bool translateVarName(const android::String8& orig, android::String8& translated);
    125 
    126     void setDetails(android::String8 details);
    127     const android::String8& getDetails() const;
    128 private:
    129     void releaseRemoteAudio();
    130 
    131 private:
    132     std::map<android::String8, android::sp<Buffer> > mBufferList;
    133     std::map<android::String8, int> mIndexList;
    134     std::map<android::String8, Value> mValueList;
    135     ClientInterface* mClient;
    136     android::String8 mDetails;
    137 };
    138 
    139 
    140 #endif // CTSAUDIO_TASKCASE_H
    141