• 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_DISTRIBUTED_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_DISTRIBUTED_H
18 
19 #include "base/memory/referenced.h"
20 #include "bridge/declarative_frontend/engine/bindings.h"
21 #include "core/common/storage/storage_proxy.h"
22 #include "frameworks/bridge/declarative_frontend/engine/js_types.h"
23 
24 namespace OHOS::Ace::Framework {
25 
26 class JSDistributed final : public Referenced {
27 public:
JSDistributed(const std::string & sessionId)28     JSDistributed(const std::string& sessionId) : sessionId_(sessionId) {}
29 
30     void Set(const JSCallbackInfo& args);
31     void Get(const JSCallbackInfo& args);
32     void Delete(const JSCallbackInfo& args);
33 
34     static void ConstructorCallback(const JSCallbackInfo& args);
35     static void DestructorCallback(JSDistributed* obj);
36 
37     static void JSBind(BindingTarget globalObj);
38 
39     void Init(const JSRef<JSObject>& object, const std::string& sessionId);
40 
41     void OnDataOnChanged(const std::string& key);
42 
43     void OnStatusNotify(const std::string& onlineStatus);
44 
45 private:
46     std::string sessionId_;
47 
48     JSRef<JSFunc> onDataOnChange_;
49     JSRef<JSFunc> onConnected_;
50     JSRef<JSObject> object_;
51     RefPtr<Storage> storage_;
52 };
53 
54 } // namespace OHOS::Ace::Framework
55 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_DISTRIBUTED_H