• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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 OHOS_BUNDLE_DAEMON_H
17 #define OHOS_BUNDLE_DAEMON_H
18 
19 #include "bundle_daemon_handler.h"
20 #include "bundle_daemon_interface.h"
21 #include "bundlems_client.h"
22 #include "nocopyable.h"
23 #include "service.h"
24 
25 namespace OHOS {
26 typedef int32_t (*InvokeFunc)(IpcIo *req);
27 class BundleDaemon : public Service, NoCopyable {
28 public:
GetInstance()29     static BundleDaemon &GetInstance()
30     {
31         static BundleDaemon instance;
32         return instance;
33     }
34     static int32_t Invoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply);
35 private:
36     static const char *GetServiceName(Service *service);
37     static BOOL ServiceInitialize(Service *service, Identity identity);
38     static TaskConfig GetServiceTaskConfig(Service *service);
39     static BOOL ServiceMessageHandle(Service *service, Request *request);
40 private:
41     BundleDaemon();
42     ~BundleDaemon();
43     Identity identity_ {};
44     BundleDaemonHandler handler_ {};
45     BundleMsClient *bundleMsClient_ { nullptr };
46 
47     static int32_t RegisterCallbackInvoke(IpcIo *req);
48     static int32_t ExtractHapInvoke(IpcIo *req);
49     static int32_t RenameFileInvoke(IpcIo *req);
50     static int32_t CreatePermissionInvoke(IpcIo *req);
51     static int32_t CreateDataDirectoryInvoke(IpcIo *req);
52     static int32_t StoreContentToFileInvoke(IpcIo *req);
53     static int32_t MoveFileInvoke(IpcIo *req);
54     static int32_t RemoveFileInvoke(IpcIo *req);
55     static int32_t RemoveInstallDirectoryInvoke(IpcIo *req);
56     static constexpr InvokeFunc invokeFuncs[BDS_CMD_END] {
57         BundleDaemon::ExtractHapInvoke,
58         BundleDaemon::RenameFileInvoke,
59         BundleDaemon::CreatePermissionInvoke,
60         BundleDaemon::CreateDataDirectoryInvoke,
61         BundleDaemon::StoreContentToFileInvoke,
62         BundleDaemon::MoveFileInvoke,
63         BundleDaemon::RemoveFileInvoke,
64         BundleDaemon::RemoveInstallDirectoryInvoke,
65     };
66 };
67 
68 struct DefaultFeatureApi {
69     INHERIT_SERVER_IPROXY;
70 };
71 
72 typedef struct {
73     INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
74     Identity identity;
75 } BundleDaemonFeature;
76 } // OHOS
77 #endif // OHOS_BUNDLE_DAEMON_H
78