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
16#ifndef FILEMANAGEMENT_DFS_SERVICE_EVENTHANDLE_DAEMON_EXECUTE_H
17#define FILEMANAGEMENT_DFS_SERVICE_EVENTHANDLE_DAEMON_EXECUTE_H
18
19#include <cstdint>
20#include <map>
21#include <mutex>
22#include <string>
23#include <vector>
24
25#include "daemon_event.h"
26#include "daemon_eventhandler.h"
27
28namespace OHOS {
29namespace Storage {
30namespace DistributedFile {
31class DaemonExecute {
32public:
33    explicit DaemonExecute();
34    void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
35
36private:
37    using ExecuteFunc = void (DaemonExecute::*)(const AppExecFwk::InnerEvent::Pointer &event);
38    void ExecutePushAsset(const AppExecFwk::InnerEvent::Pointer &event);
39    void ExecuteRequestSendFile(const AppExecFwk::InnerEvent::Pointer &event);
40    int32_t RequestSendFileInner(const std::string &srcUri,
41                                 const std::string &dstPath,
42                                 const std::string &dstDeviceId,
43                                 const std::string &sessionName);
44
45private:
46    std::string GetZipName(const std::string &relativePath);
47    std::vector<std::string> GetFileList(const std::vector<std::string> &uris,
48                                         int32_t userId,
49                                         const std::string &srcBundleName);
50    int32_t HandleZip(const std::vector<std::string> &fileList,
51                      const sptr<AssetObj> &assetObj,
52                      std::string &sendFileName,
53                      bool &isSingleFile);
54    void HandlePushAssetFail(int32_t socketId, const sptr<AssetObj> &assetObj);
55
56private:
57    std::mutex executeFuncMapMutex_;
58    std::map<uint32_t, ExecuteFunc> executeFuncMap_;
59};
60} // namespace DistributedFile
61} // namespace Storage
62} // namespace OHOS
63#endif // FILEMANAGEMENT_DFS_SERVICE_EVENTHANDLE_DAEMON_EXECUTE_H
64