• 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 DISTRIBUTEDDATASERVICE_OBJECT_SERVICE_H
17 #define DISTRIBUTEDDATASERVICE_OBJECT_SERVICE_H
18 
19 #include "feature/static_acts.h"
20 #include "object_manager.h"
21 #include "object_service_stub.h"
22 #include "visibility.h"
23 #include "object_data_listener.h"
24 
25 namespace OHOS::DistributedObject {
26 class API_EXPORT ObjectServiceImpl : public ObjectServiceStub {
27 public:
28     using Handler = std::function<void(int, std::map<std::string, std::vector<std::string>> &)>;
29     ObjectServiceImpl();
30     virtual ~ObjectServiceImpl();
31     int32_t ObjectStoreSave(const std::string &bundleName, const std::string &sessionId,
32         const std::string &deviceId, const std::map<std::string, std::vector<uint8_t>> &data,
33         sptr<IRemoteObject> callback) override;
34     int32_t ObjectStoreRetrieve(
35         const std::string &bundleName, const std::string &sessionId, sptr<IRemoteObject> callback) override;
36     int32_t ObjectStoreRevokeSave(const std::string &bundleName, const std::string &sessionId,
37         sptr<IRemoteObject> callback) override;
38     int32_t RegisterDataObserver(const std::string &bundleName, const std::string &sessionId,
39         sptr<IRemoteObject> callback) override;
40     int32_t UnregisterDataChangeObserver(const std::string &bundleName, const std::string &sessionId) override;
41     int32_t DeleteSnapshot(const std::string &bundleName, const std::string &sessionId) override;
42     int32_t IsBundleNameEqualTokenId(
43         const std::string &bundleName, const std::string &sessionId, const uint32_t &tokenId);
44     void Clear();
45     int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam &param) override;
46     int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override;
47     int32_t OnInitialize() override;
48     int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override;
49     int32_t OnBind(const BindInfo &bindInfo) override;
50     void DumpObjectServiceInfo(int fd, std::map<std::string, std::vector<std::string>> &params);
51     int32_t OnAssetChanged(const std::string &bundleName, const std::string &sessionId,
52         const std::string &deviceId, const ObjectStore::Asset &assetValue) override;
53     int32_t BindAssetStore(const std::string &bundleName, const std::string &sessionId,
54         ObjectStore::Asset &asset, ObjectStore::AssetBindInfo &bindInfo) override;
55 private:
56     using StaticActs = DistributedData::StaticActs;
57     class ObjectStatic : public StaticActs {
58     public:
~ObjectStatic()59         ~ObjectStatic() override {};
60         int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override;
61     };
62     class Factory {
63     public:
64         Factory();
65         ~Factory();
66     private:
67         std::shared_ptr<ObjectStatic> staticActs_;
68     };
69     void RegisterObjectServiceInfo();
70     void RegisterHandler();
71     static Factory factory_;
72     std::shared_ptr<ExecutorPool> executors_;
73 };
74 } // namespace OHOS::DistributedObject
75 #endif
76