• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "script_registercmd.h"
16 #include <cstring>
17 #include <dlfcn.h>
18 #include "dump.h"
19 #include "script_instruction.h"
20 #include "script_instructionhelper.h"
21 #include "script_manager.h"
22 
23 using namespace Uscript;
24 
25 namespace BasicInstruction {
Execute(UScriptEnv & env,UScriptContext & context)26 int32_t ScriptRegisterCmd::Execute(UScriptEnv &env, UScriptContext &context)
27 {
28     Updater::UPDATER_INIT_RECORD;
29     ScriptInstructionHelper* helper = ScriptInstructionHelper::GetBasicInstructionHelper();
30     if (helper == nullptr) {
31         USCRIPT_LOGE("Fail to get instruction helper");
32         UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Fail to get instruction helper");
33         return USCRIPT_INVALID_PARAM;
34     }
35 
36     std::string instrName;
37     std::string libName;
38     int32_t ret = context.GetParam(0, instrName);
39     if (ret != USCRIPT_SUCCESS) {
40         USCRIPT_LOGE("Fail to get param");
41         UPDATER_LAST_WORD(ret, "Fail to get instrName");
42         return ret;
43     }
44     ret = context.GetParam(1, libName);
45     if (ret != USCRIPT_SUCCESS) {
46         USCRIPT_LOGE("Fail to get param");
47         UPDATER_LAST_WORD(ret, "Fail to get libName");
48         return ret;
49     }
50 
51     // 动态加载对应的so,然后获取对应的指令
52     return helper->RegisterUserInstruction(libName, instrName);
53 }
54 } // namespace BasicInstruction
55