• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "sync_options.h"
17 
18 #include "device_profile_log.h"
19 #include "parcel_helper.h"
20 
21 namespace OHOS {
22 namespace DeviceProfile {
23 namespace {
24 const std::string TAG = "SyncOptions";
25 }
26 
GetDeviceList() const27 const std::list<std::string>& SyncOptions::GetDeviceList() const
28 {
29     return syncDevIds_;
30 }
31 
AddDevice(const std::string & deviceId)32 void SyncOptions::AddDevice(const std::string& deviceId)
33 {
34     syncDevIds_.emplace_back(deviceId);
35 }
36 
GetSyncMode() const37 SyncMode SyncOptions::GetSyncMode() const
38 {
39     return syncMode_;
40 }
41 
SetSyncMode(SyncMode mode)42 void SyncOptions::SetSyncMode(SyncMode mode)
43 {
44     syncMode_ = mode;
45 }
46 
Marshalling(Parcel & parcel) const47 bool SyncOptions::Marshalling(Parcel& parcel) const
48 {
49     PARCEL_WRITE_HELPER_RET(parcel, Int32, static_cast<int32_t>(syncMode_), false);
50     PARCEL_WRITE_HELPER_RET(parcel, Int32, static_cast<int32_t>(syncDevIds_.size()), false);
51     for (const auto& deviceId : syncDevIds_) {
52         PARCEL_WRITE_HELPER_RET(parcel, String, deviceId, false);
53     }
54     return true;
55 }
56 
Unmarshalling(Parcel & parcel)57 bool SyncOptions::Unmarshalling(Parcel& parcel)
58 {
59     int32_t mode = 0;
60     PARCEL_READ_HELPER_RET(parcel, Int32, mode, false);
61     syncMode_ = static_cast<DeviceProfile::SyncMode>(mode);
62     int32_t size = 0;
63     PARCEL_READ_HELPER_RET(parcel, Int32, size, false);
64     for (int32_t i = 0; i < size; i++) {
65         std::string deviceId;
66         PARCEL_READ_HELPER_RET(parcel, String, deviceId, false);
67         syncDevIds_.emplace_back(deviceId);
68     }
69     return true;
70 }
71 } // namespace DeviceProfile
72 } // namespace OHOS