• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #ifndef JSVM_PLATFORM_H
17 #define JSVM_PLATFORM_H
18 #include <cstdint>
19 #include <cstdio>
20 #include <cstdlib>
21 #include <fstream>
22 #include <securec.h>
23 #include <string>
24 
25 #ifdef TARGET_OHOS
26 #include "platform/platform_ohos.h"
27 #define OHOS_CALL(api_call) api_call
28 #define OHOS_SELECT(expr_ohos, expr_non_ohos) expr_ohos
29 #else
30 #define OHOS_CALL(api_call)
31 #define OHOS_SELECT(expr_ohos, expr_non_ohos) expr_non_ohos
32 #endif
33 
34 namespace platform {
35 class OS {
36 public:
37     [[noreturn]] static void Abort();
38     static uint64_t GetUid();
39     static uint64_t GetPid();
40     static uint64_t GetTid();
41 
42     enum class LogLevel : uint64_t { LOG_DEBUG = 0, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
43 
44     static void Print(LogLevel level, const char* format, ...) __attribute__((format(printf, 2, 3)));
45     static void PrintString(LogLevel level, const char* string);
46 };
47 
48 class RunJsTrace {
49 public:
50     explicit RunJsTrace(bool runJs);
51     explicit RunJsTrace(const char* name);
52 
53     ~RunJsTrace();
54 
55 private:
56     bool runJs;
57 };
58 } // namespace platform
59 
60 #endif
61