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_TASKGENERIC_H 19 #define CTSAUDIO_TASKGENERIC_H 20 #include <string.h> 21 #include <stdio.h> 22 #include <list> 23 #include <map> 24 #include <set> 25 #include <utils/String8.h> 26 27 28 class TaskCase; 29 30 class TaskGeneric { 31 public: 32 // internal model for xml tags 33 enum TaskType { 34 ETaskInvalid = 0, 35 ETaskBatch = 1, 36 ETaskCase = 2, 37 ETaskSetup = 3, 38 ETaskAction = 4, 39 ETaskSequential = 5, 40 ETaskProcess = 6, 41 ETaskInput = 7, 42 ETaskOutput = 8, 43 ETaskSound = 9, 44 ETaskSave = 10, 45 ETaskMessage = 11, 46 ETaskDownload = 12, 47 ETaskInvalidLast = 13, 48 //no ETaskInclude include does not involve any action. 49 }; 50 51 TaskGeneric(TaskType type); 52 53 virtual ~TaskGeneric(); 54 getType()55 inline TaskType getType() { 56 return mType; 57 } 58 59 enum ExecutionResult { 60 EResultOK = 0, 61 // continue in the current loop. will result in skipping all subsequent steps 62 EResultContinue = 1, 63 // get out of the current loop 64 EResultBreakOneLoop = 2, 65 // error which cannot be continued. effect is the same as fail. stops everything. 66 EResultError = 3, 67 // test failed. stops everything. 68 EResultFail = 4, 69 // test passed. 70 EResultPass = 5 71 }; 72 73 /** 74 * default implementation for adding child action 75 * Ownership of the child is passed to this instance, and child will be destroyed in parent's 76 * destructor. 77 * @return false on error 78 */ 79 virtual bool addChild(TaskGeneric* child); 80 81 virtual ExecutionResult run(); 82 83 /// can be NULL if parent does not exist 84 TaskGeneric* getParent(); 85 /// can be NULL if TestCase does not exist (unit testing?) 86 TaskCase* getTestCase(); 87 88 void setParent(TaskGeneric* parent); 89 90 /** 91 * parse attribute from XML DOM. name/value pair will be passed for all attributes. 92 */ 93 virtual bool parseAttribute(const android::String8& name, const android::String8& value); 94 95 bool forEachChild(bool (*runForEachChild)(TaskGeneric* child, void* data), void* data); 96 97 protected: 98 /// used by child instance to register allowed attributes 99 /// keys array should end with NULL 100 void registerSupportedStringAttributes(const android::String8* keys[]); 101 bool addStringAttribute(const android::String8& key, const android::String8& value); 102 bool findStringAttribute(const android::String8& key, android::String8& value) const; getChildren()103 inline std::list<TaskGeneric*>& getChildren() { 104 return mChildren; 105 }; 106 107 private: 108 TaskType mType; 109 TaskGeneric* mParent; 110 std::list<TaskGeneric*> mChildren; 111 112 std::set<android::String8> mAllowedStringAttributes; 113 std::map<android::String8, android::String8> mStringAttributes; 114 115 }; 116 117 118 #endif // CTSAUDIO_TASKGENERIC_H 119