• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 BUNDLE_FRAMEWORK_INTERFACES_KITS_JS_BUNDLE_MONITOR_BUNDLE_MONITOR_CALLBACK_H
17 #define BUNDLE_FRAMEWORK_INTERFACES_KITS_JS_BUNDLE_MONITOR_BUNDLE_MONITOR_CALLBACK_H
18 
19 #include <future>
20 #include <vector>
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 
24 #include "common_event_manager.h"
25 #include "common_event_support.h"
26 #include "common_event_subscriber.h"
27 #include "common_event_subscribe_info.h"
28 #include "event_listener.h"
29 #include "iremote_stub.h"
30 #include "nocopyable.h"
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 class BundleMonitorCallback : public EventFwk::CommonEventSubscriber {
35 public:
36     explicit BundleMonitorCallback(const EventFwk::CommonEventSubscribeInfo &subscribeInfo);
37     virtual ~BundleMonitorCallback();
38     void BundleMonitorOn(napi_env env, napi_value handler, const std::string &type);
39     void BundleMonitorOff(napi_env env, napi_value handler, const std::string &type);
40     void BundleMonitorOff(napi_env env, const std::string &type);
41     void OnReceiveEvent(const EventFwk::CommonEventData &eventData);
42 private:
43     void EventListenerAdd(napi_env env, napi_value handler,
44         std::vector<std::shared_ptr<EventListener>> &eventListeners, const std::string &type);
45     void EventListenerDelete(napi_env env, napi_value handler,
46         const std::vector<std::shared_ptr<EventListener>> &eventListeners);
47     void EventListenerDeleteAll(napi_env env, const std::vector<std::shared_ptr<EventListener>> &eventListeners);
48     void BundleMonitorEmit(const std::string &type, std::string &bundleName, int32_t userId, int32_t appIndex);
49     void EventListenerEmit(std::string &bundleName, int32_t userId, int32_t appIndex,
50         const std::vector<std::shared_ptr<EventListener>> &eventListeners);
51 private:
52     std::vector<std::shared_ptr<EventListener>> addListeners;
53     std::vector<std::shared_ptr<EventListener>> updateListeners;
54     std::vector<std::shared_ptr<EventListener>> removeListeners;
55     DISALLOW_COPY_AND_MOVE(BundleMonitorCallback);
56 };
57 }
58 }
59 
60 #endif // BUNDLE_FRAMEWORK_INTERFACES_KITS_JS_BUNDLE_MONITOR_BUNDLE_MONITOR_CALLBACK_H