1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef USCRIPT_MANAGER_IMPL_H 16 #define USCRIPT_MANAGER_IMPL_H 17 18 #include <map> 19 #include <memory> 20 #include <vector> 21 #include "pkg_manager.h" 22 #include "script_instruction.h" 23 #include "script_manager.h" 24 #include "thread_pool.h" 25 26 namespace Uscript { 27 class ScriptInstructionHelper; 28 class ScriptManagerImpl : public ScriptManager { 29 public: 30 friend class ScriptInterpreter; 31 friend class ScriptInstructionHelper; 32 ScriptManagerImpl(UScriptEnv * env)33 explicit ScriptManagerImpl(UScriptEnv *env) : scriptEnv_(env) {} 34 virtual ~ScriptManagerImpl(); 35 int32_t Init(); 36 int32_t ExecuteScript(int32_t priority) override; 37 38 private: 39 int32_t ExtractAndExecuteScript(Hpackage::PkgManager::PkgManagerPtr manager, 40 const std::string &scriptName); 41 int32_t AddScript(const std::string &scriptName, int32_t priority); 42 int32_t AddInstruction(const std::string &instrName, const UScriptInstructionPtr instruction); 43 UScriptInstruction* FindInstruction(const std::string &instrName); 44 UScriptEnv* GetScriptEnv(const std::string &instrName) const; 45 int32_t RegisterInstruction(ScriptInstructionHelper &helper); 46 private: 47 static const int32_t MAX_THREAD_POOL = 4; 48 std::map<std::string, UScriptInstructionPtr> scriptInstructions_; 49 std::vector<std::string> scriptFiles_[MAX_PRIORITY] {}; 50 ThreadPool *threadPool_ = nullptr; 51 UScriptEnv *scriptEnv_ = nullptr; 52 }; 53 } // namespace Uscript 54 #endif 55