• 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 
21 using json = nlohmann::json;
22 
23 namespace OHOS {
24 namespace DistributedHardware {
SetDisplayId(uint64_t displayId)25 void DScreenMapRelation::SetDisplayId(uint64_t displayId)
26 {
27     displayId_ = displayId;
28 }
29 
GetDisplayId() const30 uint64_t DScreenMapRelation::GetDisplayId() const
31 {
32     return displayId_;
33 }
34 
SetScreenId(uint64_t screenId)35 void DScreenMapRelation::SetScreenId(uint64_t screenId)
36 {
37     screenId_ = screenId;
38 }
39 
GetScreenId() const40 uint64_t DScreenMapRelation::GetScreenId() const
41 {
42     return screenId_;
43 }
44 
SetDisplayRect(const DisplayRect & displayRect)45 void DScreenMapRelation::SetDisplayRect(const DisplayRect &displayRect)
46 {
47     displayRect_ = displayRect;
48 }
49 
GetDisplayRect()50 DisplayRect& DScreenMapRelation::GetDisplayRect()
51 {
52     return displayRect_;
53 }
54 
SetScreenRect(const ScreenRect & screenRect)55 void DScreenMapRelation::SetScreenRect(const ScreenRect &screenRect)
56 {
57     screenRect_ = screenRect;
58 }
59 
GetScreenRect()60 ScreenRect& DScreenMapRelation::GetScreenRect()
61 {
62     return screenRect_;
63 }
64 
to_json(json & j,const DScreenMapRelation & dScreenMapRelation)65 void to_json(json &j, const DScreenMapRelation &dScreenMapRelation)
66 {
67     json displayRectJson;
68     json screenRectJson;
69     to_json(displayRectJson, dScreenMapRelation.displayRect_);
70     to_json(screenRectJson, dScreenMapRelation.screenRect_);
71     j = json {
72         {KEY_DISPLAY_ID, dScreenMapRelation.displayId_},
73         {KEY_SCREEN_ID, dScreenMapRelation.screenId_},
74         {KEY_DISPLAY_RECT, displayRectJson},
75         {KEY_SCREEN_RECT, screenRectJson}
76     };
77 }
78 
from_json(const json & j,DScreenMapRelation & dScreenMapRelation)79 void from_json(const json &j, DScreenMapRelation &dScreenMapRelation)
80 {
81     j.at(KEY_DISPLAY_ID).get_to(dScreenMapRelation.displayId_);
82     j.at(KEY_SCREEN_ID).get_to(dScreenMapRelation.screenId_);
83     from_json(j.at(KEY_DISPLAY_RECT), dScreenMapRelation.displayRect_);
84     from_json(j.at(KEY_SCREEN_RECT), dScreenMapRelation.screenRect_);
85 }
86 
to_json(json & j,const DisplayRect & rect)87 void to_json(json &j, const DisplayRect &rect)
88 {
89     j = json {
90         {KEY_POINT_START_X, rect.startX},
91         {KEY_POINT_START_Y, rect.startY},
92         {KEY_WIDTH, rect.width},
93         {KEY_HEIGHT, rect.height}
94     };
95 }
96 
from_json(const json & j,DisplayRect & rect)97 void from_json(const json &j, DisplayRect &rect)
98 {
99     j.at(KEY_POINT_START_X).get_to(rect.startX);
100     j.at(KEY_POINT_START_Y).get_to(rect.startY);
101     j.at(KEY_WIDTH).get_to(rect.width);
102     j.at(KEY_HEIGHT).get_to(rect.height);
103 }
104 
to_json(json & j,const ScreenRect & rect)105 void to_json(json &j, const ScreenRect &rect)
106 {
107     j = json {
108         {KEY_POINT_START_X, rect.startX},
109         {KEY_POINT_START_Y, rect.startY},
110         {KEY_WIDTH, rect.width},
111         {KEY_HEIGHT, rect.height}
112     };
113 }
114 
from_json(const json & j,ScreenRect & rect)115 void from_json(const json &j, ScreenRect &rect)
116 {
117     j.at(KEY_POINT_START_X).get_to(rect.startX);
118     j.at(KEY_POINT_START_Y).get_to(rect.startY);
119     j.at(KEY_WIDTH).get_to(rect.width);
120     j.at(KEY_HEIGHT).get_to(rect.height);
121 }
122 } // namespace DistributedHardware
123 } // namespace OHOS