• 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 FILE_ACCESS_NOTIFY_COMMON_H
17 #define FILE_ACCESS_NOTIFY_COMMON_H
18 
19 #include <string>
20 
21 #include "file_access_extension_info.h"
22 #include "hilog_wrapper.h"
23 #include "parcel.h"
24 
25 namespace OHOS {
26 namespace FileAccessFwk {
27 constexpr int32_t NOTIFY_DEVICE_ONLINE = 1;
28 constexpr int32_t NOTIFY_DEVICE_OFFLINE = 2;
29 
30 struct NotifyMessage : public virtual OHOS::Parcelable {
31 public:
32     int32_t deviceType;
33     int32_t notifyType;
34     std::string srcUri;     // source uri when notifyType is (NOTIFY_FILE_MOVE/NOTIFY_FILE_RENAME), other case is "".
35     std::string dstUri;     // destination uri for all notifyType
36 
37     NotifyMessage() = default;
NotifyMessageNotifyMessage38     NotifyMessage(const int32_t deviceTypeIn, const int32_t notifyTypeIn, const std::string &srcUriIn,
39         const std::string &dstUriIn)
40         : deviceType(deviceTypeIn), notifyType(notifyTypeIn), srcUri(srcUriIn), dstUri(dstUriIn)
41     {}
42 
ReadFromParcelNotifyMessage43     void ReadFromParcel(Parcel &parcel)
44     {
45         deviceType = parcel.ReadInt32();
46         notifyType = parcel.ReadInt32();
47         srcUri = parcel.ReadString();
48         dstUri = parcel.ReadString();
49     }
50 
MarshallingNotifyMessage51     virtual bool Marshalling(Parcel &parcel) const override
52     {
53         if (!parcel.WriteInt32(deviceType)) {
54             HILOG_ERROR("NotifyMessage Unmarshalling error:write deviceType fail.");
55             return false;
56         }
57         if (!parcel.WriteInt32(notifyType)) {
58             HILOG_ERROR("NotifyMessage Unmarshalling error:write notifyType fail.");
59             return false;
60         }
61         if (!parcel.WriteString(srcUri)) {
62             HILOG_ERROR("NotifyMessage Unmarshalling error:write srcUri fail.");
63             return false;
64         }
65         if (!parcel.WriteString(dstUri)) {
66             HILOG_ERROR("NotifyMessage Unmarshalling error:write dstUri fail.");
67             return false;
68         }
69         return true;
70     }
71 
UnmarshallingNotifyMessage72     static NotifyMessage *Unmarshalling(Parcel &parcel)
73     {
74         NotifyMessage *message = new(std::nothrow) NotifyMessage();
75         if (message == nullptr) {
76             HILOG_ERROR("NotifyMessage Unmarshalling error:new object fail.");
77             return nullptr;
78         }
79         message->ReadFromParcel(parcel);
80         return message;
81     }
82 };
83 } // namespace FileAccessFwk
84 } // namespace OHOS
85 #endif // FILE_ACCESS_NOTIFY_COMMON_H