• 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 
16 #ifndef NAPI_IPC_OHOS_ASHMEM_H
17 #define NAPI_IPC_OHOS_ASHMEM_H
18 
19 #include "napi/native_api.h"
20 #include "napi/native_common.h"
21 #include "napi/native_node_api.h"
22 #include "ashmem.h"
23 
24 namespace OHOS {
25 class NAPIAshmem {
26 public:
27     enum {
28         PROT_EXEC = 4,
29         PROT_NONE = 0,
30         PROT_READ = 1,
31         PROT_WRITE = 2,
32     };
33     explicit NAPIAshmem(sptr<Ashmem> &ashmem);
NAPIAshmem()34     NAPIAshmem():ashmem_(nullptr) {}
35     ~NAPIAshmem() = default;
GetAshmem()36     const sptr<Ashmem> &GetAshmem()
37     {
38         return ashmem_;
39     }
SetAshmem(sptr<Ashmem> & ashmem)40     void SetAshmem(sptr<Ashmem> &ashmem)
41     {
42         ashmem_ = ashmem;
43     }
44     static napi_value AshmemExport(napi_env env, napi_value exports);
45 private:
46     static napi_value Ashmem_JS_Constructor(napi_env env, napi_callback_info cbinfo);
47     static napi_value CloseAshmem(napi_env env, napi_callback_info info);
48     static napi_value CreateAshmem(napi_env env, napi_callback_info info);
49     static napi_value CreateAshmemFromExisting(napi_env env, napi_callback_info info);
50     static napi_value GetAshmemSize(napi_env env, napi_callback_info info);
51     static napi_value MapAshmem(napi_env env, napi_callback_info info);
52     static napi_value MapReadAndWriteAshmem(napi_env env, napi_callback_info info);
53     static napi_value MapReadOnlyAshmem(napi_env env, napi_callback_info info);
54     static napi_value ReadFromAshmem(napi_env env, napi_callback_info info);
55     static napi_value SetProtection(napi_env env, napi_callback_info info);
56     static napi_value UnmapAshmem(napi_env env, napi_callback_info info);
57     static napi_value WriteToAshmem(napi_env env, napi_callback_info info);
58     sptr<Ashmem> ashmem_;
59 };
60 } // namespace OHOS
61 #endif
62