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 
24 namespace OHOS::DistributedObject {
25 class ObjectServiceImpl : public ObjectServiceStub {
26 public:
27     using Handler = std::function<void(int, std::map<std::string, std::vector<std::string>> &)>;
28     ObjectServiceImpl();
29     virtual ~ObjectServiceImpl();
30     int32_t ObjectStoreSave(const std::string &bundleName, const std::string &sessionId,
31         const std::string &deviceId, const std::map<std::string, std::vector<uint8_t>> &data,
32         sptr<IRemoteObject> callback) override;
33     int32_t ObjectStoreRetrieve(
34         const std::string &bundleName, const std::string &sessionId, sptr<IRemoteObject> callback) override;
35     int32_t ObjectStoreRevokeSave(const std::string &bundleName, const std::string &sessionId,
36         sptr<IRemoteObject> callback) override;
37     int32_t RegisterDataObserver(const std::string &bundleName, const std::string &sessionId,
38         sptr<IRemoteObject> callback) override;
39     int32_t UnregisterDataChangeObserver(const std::string &bundleName, const std::string &sessionId) override;
40     int32_t DeleteSnapshot(const std::string &bundleName, const std::string &sessionId) override;
41     int32_t IsBundleNameEqualTokenId(
42         const std::string &bundleName, const std::string &sessionId, const uint32_t &tokenId);
43     void Clear();
44     int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam &param) override;
45     int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override;
46     int32_t OnInitialize() override;
47     int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override;
48     int32_t OnBind(const BindInfo &bindInfo) override;
49     void DumpObjectServiceInfo(int fd, std::map<std::string, std::vector<std::string>> &params);
50     int32_t OnAssetChanged(const std::string &bundleName, const std::string &sessionId,
51         const std::string &deviceId, const ObjectStore::Asset &assetValue) override;
52     int32_t BindAssetStore(const std::string &bundleName, const std::string &sessionId,
53         ObjectStore::Asset &asset, ObjectStore::AssetBindInfo &bindInfo) override;
54     int32_t IsContinue(bool &result) 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