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 HNP_API_H
17#define HNP_API_H
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23typedef enum {
24    OPTION_INDEX_FORCE = 0,     /* installed forcely */
25    OPTION_INDEX_BUTT
26} HnpInstallOptionIndex;
27
28#define HNP_API_ERRNO_BASE 0x2000
29
30// 0x2001 参数非法
31#define HNP_API_ERRNO_PARAM_INVALID             (HNP_API_ERRNO_BASE + 0x1)
32
33// 0x2002 fork子进程失败
34#define HNP_API_ERRNO_FORK_FAILED               (HNP_API_ERRNO_BASE + 0x2)
35
36// 0x2003 等待子进程退出失败
37#define HNP_API_WAIT_PID_FAILED                 (HNP_API_ERRNO_BASE + 0x3)
38
39// 0x2004 非开发者模式
40#define HNP_API_NOT_IN_DEVELOPER_MODE           (HNP_API_ERRNO_BASE + 0x4)
41
42// 0x2005 创建管道失败
43#define HNP_API_ERRNO_PIPE_CREATED_FAILED       (HNP_API_ERRNO_BASE + 0x5)
44
45// 0x2006 读取管道失败
46#define HNP_API_ERRNO_PIPE_READ_FAILED          (HNP_API_ERRNO_BASE + 0x6)
47
48// 0x2007 获取返回码失败
49#define HNP_API_ERRNO_RETURN_VALUE_GET_FAILED   (HNP_API_ERRNO_BASE + 0x7)
50
51// 0x2008 移动内存失败
52#define HNP_API_ERRNO_MEMMOVE_FAILED            (HNP_API_ERRNO_BASE + 0x8)
53
54// 0x2009 产品不支持安装hnp软件包
55#define HNP_API_ERRNO_HNP_INSTALL_DISABLED      (HNP_API_ERRNO_BASE + 0x9)
56
57#define PACK_NAME_LENTH 256
58#define HAP_PATH_LENTH 256
59#define ABI_LENTH 128
60
61typedef struct HapInfo {
62    char packageName[PACK_NAME_LENTH]; // package name
63    char hapPath[HAP_PATH_LENTH];      // hap file path
64    char abi[ABI_LENTH];               // system abi
65} HapInfo;
66
67/**
68 * Install native software package.
69 *
70 * @param userId Indicates id of user.
71 * @param hnpRootPath  Indicates the root path of hnp packages
72 * @param hapInfo Indicates the information of HAP.
73 * @param installOptions Indicates install options.
74 *
75 * @return 0:success;other means failure.
76 */
77int NativeInstallHnp(const char *userId, const char *hnpRootPath, const HapInfo *hapInfo, int installOptions);
78
79/**
80 * Uninstall native software package.
81 *
82 * @param userId Indicates id of user.
83 * @param packageName Indicates the packageName of HAP.
84 *
85 * @return 0:success;other means failure.
86 */
87int NativeUnInstallHnp(const char *userId, const char *packageName);
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif