• 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 #include "dscreen_maprelation.h"
17 
18 #include "dscreen_constants.h"
19 #include "dscreen_errcode.h"
20 #include "dscreen_json_util.h"
21 
22 using json = nlohmann::json;
23 
24 namespace OHOS {
25 namespace DistributedHardware {
SetDisplayId(uint64_t displayId)26 void DScreenMapRelation::SetDisplayId(uint64_t displayId)
27 {
28     displayId_ = displayId;
29 }
30 
GetDisplayId() const31 uint64_t DScreenMapRelation::GetDisplayId() const
32 {
33     return displayId_;
34 }
35 
SetScreenId(uint64_t screenId)36 void DScreenMapRelation::SetScreenId(uint64_t screenId)
37 {
38     screenId_ = screenId;
39 }
40 
GetScreenId() const41 uint64_t DScreenMapRelation::GetScreenId() const
42 {
43     return screenId_;
44 }
45 
SetDisplayRect(const DisplayRect & displayRect)46 void DScreenMapRelation::SetDisplayRect(const DisplayRect &displayRect)
47 {
48     displayRect_ = displayRect;
49 }
50 
GetDisplayRect()51 DisplayRect& DScreenMapRelation::GetDisplayRect()
52 {
53     return displayRect_;
54 }
55 
SetScreenRect(const ScreenRect & screenRect)56 void DScreenMapRelation::SetScreenRect(const ScreenRect &screenRect)
57 {
58     screenRect_ = screenRect;
59 }
60 
GetScreenRect()61 ScreenRect& DScreenMapRelation::GetScreenRect()
62 {
63     return screenRect_;
64 }
65 
to_json(json & j,const DScreenMapRelation & dScreenMapRelation)66 void to_json(json &j, const DScreenMapRelation &dScreenMapRelation)
67 {
68     json displayRectJson;
69     json screenRectJson;
70     to_json(displayRectJson, dScreenMapRelation.displayRect_);
71     to_json(screenRectJson, dScreenMapRelation.screenRect_);
72     j = json {
73         {KEY_DISPLAY_ID, dScreenMapRelation.displayId_},
74         {KEY_SCREEN_ID, dScreenMapRelation.screenId_},
75         {KEY_DISPLAY_RECT, displayRectJson},
76         {KEY_SCREEN_RECT, screenRectJson}
77     };
78 }
79 
from_json(const json & j,DScreenMapRelation & dScreenMapRelation)80 void from_json(const json &j, DScreenMapRelation &dScreenMapRelation)
81 {
82     if (!IsUInt64(j, KEY_DISPLAY_ID) || !IsUInt64(j, KEY_SCREEN_ID)) {
83         return;
84     }
85     dScreenMapRelation.displayId_ = j[KEY_DISPLAY_ID].get<uint64_t>();
86     dScreenMapRelation.screenId_ = j[KEY_SCREEN_ID].get<uint64_t>();
87 
88     from_json(j.at(KEY_DISPLAY_RECT), dScreenMapRelation.displayRect_);
89     from_json(j.at(KEY_SCREEN_RECT), dScreenMapRelation.screenRect_);
90 }
91 
to_json(json & j,const DisplayRect & rect)92 void to_json(json &j, const DisplayRect &rect)
93 {
94     j = json {
95         {KEY_POINT_START_X, rect.startX},
96         {KEY_POINT_START_Y, rect.startY},
97         {KEY_WIDTH, rect.width},
98         {KEY_HEIGHT, rect.height}
99     };
100 }
101 
from_json(const json & j,DisplayRect & rect)102 void from_json(const json &j, DisplayRect &rect)
103 {
104     if (!IsInt32(j, KEY_POINT_START_X) || !IsInt32(j, KEY_POINT_START_Y) ||
105         !IsInt32(j, KEY_WIDTH) || !IsInt32(j, KEY_HEIGHT)) {
106         return;
107     }
108     rect.startX = j[KEY_POINT_START_X].get<int32_t>();
109     rect.startY = j[KEY_POINT_START_Y].get<int32_t>();
110     rect.width = j[KEY_WIDTH].get<int32_t>();
111     rect.height = j[KEY_HEIGHT].get<int32_t>();
112 }
113 
to_json(json & j,const ScreenRect & rect)114 void to_json(json &j, const ScreenRect &rect)
115 {
116     j = json {
117         {KEY_POINT_START_X, rect.startX},
118         {KEY_POINT_START_Y, rect.startY},
119         {KEY_WIDTH, rect.width},
120         {KEY_HEIGHT, rect.height}
121     };
122 }
123 
from_json(const json & j,ScreenRect & rect)124 void from_json(const json &j, ScreenRect &rect)
125 {
126     if (!IsInt32(j, KEY_POINT_START_X) || !IsInt32(j, KEY_POINT_START_Y) ||
127         !IsUInt32(j, KEY_WIDTH) || !IsUInt32(j, KEY_HEIGHT)) {
128         return;
129     }
130     rect.startX = j[KEY_POINT_START_X].get<int32_t>();
131     rect.startY = j[KEY_POINT_START_Y].get<int32_t>();
132     rect.width = j[KEY_WIDTH].get<uint32_t>();
133     rect.height = j[KEY_HEIGHT].get<uint32_t>();
134 }
135 } // namespace DistributedHardware
136 } // namespace OHOS