• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 DISTRIBUTEDFILE_SERVICE_H
17 #define DISTRIBUTEDFILE_SERVICE_H
18 
19 #include "distributedfile_service_stub.h"
20 #include "iremote_stub.h"
21 #include "system_ability.h"
22 
23 #include <mutex>
24 
25 namespace OHOS {
26 namespace Storage {
27 namespace DistributedFile {
28 class DistributedFileService : public SystemAbility,
29                                public DistributedFileServiceStub,
30                                public std::enable_shared_from_this<DistributedFileService> {
DECLARE_SYSTEM_ABILITY(DistributedFileService)31     DECLARE_SYSTEM_ABILITY(DistributedFileService)
32 public:
33     explicit DistributedFileService(int32_t saId, bool runOnCreate = true) : SystemAbility(saId, runOnCreate) {}
~DistributedFileService()34     ~DistributedFileService() {}
35     void OnDump() override;
36     void OnStart() override;
37     void OnStop() override;
38 
39     int32_t SendFile(const std::string &cid,
40                      const std::vector<std::string> &sourceFileList,
41                      const std::vector<std::string> &destinationFileList,
42                      const uint32_t fileCount) override;
43     int32_t OpenFile(int32_t fd, const std::string &fileName, int32_t mode) override;
44     int32_t RegisterNotifyCallback(sptr<IFileTransferCallback> &callback) override;
45     int32_t UnRegisterNotifyCallback() override;
46     int32_t IsDeviceOnline(const std::string &cid) override;
47 
48     static inline const std::string pkgName_ { "ohos.storage.distributedfile.service" };
49 private:
50     void PublishSA();
51     void StartManagers();
52     int32_t CreateSourceResources(const std::vector<std::string> &sourceFileList, std::vector<char *> &sFileList);
53     int32_t CreateDestResources(const std::vector<std::string> &destinationFileList, std::vector<char *> &dFileList);
54     void DestroyFileList(std::vector<char *> &fileList);
55 };
56 } // namespace DistributedFile
57 } // namespace Storage
58 } // namespace OHOS
59 #endif // DISTRIBUTEDFILE_SERVICE_H
60