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 #ifndef INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_SHORT_TERM_CALLBACK_H
16 #define INTERFACES_KITS_JS_MEDIALIBRARY_INCLUDE_SHORT_TERM_CALLBACK_H
17 
18 #include <js_native_api.h>
19 #include <napi/native_api.h>
20 #include <node_api.h>
21 #include <string>
22 #include <uv.h>
23 
24 #include "want.h"
25 #include "ui_content.h"
26 #include "medialibrary_client_errno.h"
27 
28 namespace OHOS {
29 namespace Media {
30 
31 class ShortTermCallback {
32 public:
33     explicit ShortTermCallback(napi_env env, Ace::UIContent *uiContent);
34     virtual ~ShortTermCallback() = default;
35     void OnRelease(int32_t releaseCode);
36     void OnResult(int32_t resultCode, const OHOS::AAFwk::Want &want);
37     void OnReceive(const OHOS::AAFwk::WantParams &request);
38     void OnError(int32_t code, const std::string &name, const std::string &message);
39     void SetSessionId(int32_t sessionId);
40     void SetFunc(napi_value func);
41 
42 private:
43     int32_t sessionId_ = 0;
44     int32_t resultCode_ = JS_ERR_PERMISSION_DENIED;
45     napi_env env_ = nullptr;
46     napi_ref callbackRef = nullptr;
47     Ace::UIContent *uiContent = nullptr;
48     void SendMessageBack(const std::string &desFileUri);
49     void CloseModalUIExtension();
50 };
51 }
52 }
53 #endif
54