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 UPDATER_INTERFACE_H
17 #define UPDATER_INTERFACE_H
18 
19 #include <memory>
20 
21 #include "base_client.h"
22 #include "base_session.h"
23 #include "client_helper.h"
24 #include "session_manager.h"
25 #include "update_result.h"
26 
27 namespace OHOS::UpdateEngine {
28 class IUpdater : public BaseClient {
29 public:
~IUpdater()30     virtual ~IUpdater() {}
31 
32     napi_value On(napi_env env, napi_callback_info info);
33     napi_value Off(napi_env env, napi_callback_info info);
34     virtual void GetUpdateResult(uint32_t type, UpdateResult &result);
35 
36 protected:
RegisterCallback()37     virtual void RegisterCallback() {}
UnRegisterCallback()38     virtual void UnRegisterCallback() {}
39 
RemoveSession(uint32_t sessionId)40     void RemoveSession(uint32_t sessionId) override
41     {
42         if (sessionsMgr_ == nullptr) {
43             return;
44         }
45         sessionsMgr_->RemoveSession(sessionId);
46     }
47 
48     napi_value StartSession(napi_env env, napi_callback_info info, SessionParams &sessionParams,
49         BaseSession::DoWorkFunction function);
50     napi_value StartParamErrorSession(napi_env env, napi_callback_info info, CALLBACK_POSITION callbackPosition);
51     void NotifyEventInfo(const EventInfo &eventInfo);
52 
53 protected:
54     std::shared_ptr<SessionManager> sessionsMgr_ = nullptr;
55 };
56 } // namespace OHOS::UpdateEngine
57 #endif // UPDATER_INTERFACE_H