1 /***************************************************************************
2 *
3 * Copyright 2012 BMW Car IT GmbH
4 *
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ****************************************************************************/
19
20 #include "ilm_control.h"
21 #include "LMControl.h"
22
23 #include <cstring>
24
25 #include <iostream>
26 using std::cout;
27 using std::cin;
28 using std::cerr;
29 using std::endl;
30
31
32 #include <iomanip>
33 using std::dec;
34 using std::hex;
35
36
37 #include <pthread.h>
38 #include <signal.h>
39 #include <sys/types.h>
40 #include <unistd.h>
41
layerNotificationCallback(t_ilm_layer layer,struct ilmLayerProperties * properties,t_ilm_notification_mask mask)42 void layerNotificationCallback(t_ilm_layer layer, struct ilmLayerProperties* properties, t_ilm_notification_mask mask)
43 {
44 cout << "\nNotification: layer " << layer << " updated properties:\n";
45
46 if (ILM_NOTIFICATION_VISIBILITY & mask)
47 {
48 cout << "\tvisibility = " << properties->visibility << "\n";
49 }
50
51 if (ILM_NOTIFICATION_OPACITY & mask)
52 {
53 cout << "\topacity = " << properties->opacity << "\n";
54 }
55
56 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
57 {
58 cout << "\tsource rect = x:" << properties->sourceX
59 << ", y:" << properties->sourceY
60 << ", width:" << properties->sourceWidth
61 << ", height:" << properties->sourceHeight
62 << "\n";
63 }
64
65 if (ILM_NOTIFICATION_DEST_RECT & mask)
66 {
67 cout << "\tdest rect = x:" << properties->destX
68 << ", y:" << properties->destY
69 << ", width:" << properties->destWidth
70 << ", height:" << properties->destHeight
71 << "\n";
72 }
73 }
74
testNotificationLayer(t_ilm_layer layerid)75 void testNotificationLayer(t_ilm_layer layerid)
76 {
77 cout << "Setup notification for layer " << layerid << " \n";
78
79 ilmErrorTypes callResult = ilm_layerAddNotification(layerid, layerNotificationCallback);
80 if (ILM_SUCCESS != callResult)
81 {
82 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
83 cout << "Failed to add notification callback to layer with ID " << layerid << "\n";
84 return;
85 }
86
87 for (int i = 0; i < 2; ++i)
88 {
89 usleep(100 * 1000);
90 cout << "Set layer 1000 visbility to FALSE\n";
91 ilm_layerSetVisibility(layerid, ILM_FALSE);
92 ilm_commitChanges();
93
94 usleep(100 * 1000);
95 cout << "Set layer 1000 visbility to TRUE\n";
96 ilm_layerSetVisibility(layerid, ILM_TRUE);
97
98 cout << "Set layer 1000 opacity to 0.3\n";
99 ilm_layerSetOpacity(layerid, 0.3);
100 ilm_commitChanges();
101
102 usleep(100 * 1000);
103 cout << "Set layer 1000 opacity to 1.0\n";
104 ilm_layerSetOpacity(layerid, 1.0);
105 ilm_commitChanges();
106 }
107
108 ilm_commitChanges(); // make sure, app lives long enough to receive last notification
109 }
110
watchLayer(unsigned int * layerids,unsigned int layeridCount)111 void watchLayer(unsigned int* layerids, unsigned int layeridCount)
112 {
113 for (unsigned int i = 0; i < layeridCount; ++i)
114 {
115 unsigned int layerid = layerids[i];
116 cout << "Setup notification for layer " << layerid << "\n";
117
118 ilmErrorTypes callResult = ilm_layerAddNotification(layerid, layerNotificationCallback);
119 if (ILM_SUCCESS != callResult)
120 {
121 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
122 cout << "Failed to add notification callback to layer with ID " << layerid << "\n";
123 return;
124 }
125 }
126
127 cout << "Waiting for notifications...\n";
128 int block;
129 cin >> block;
130
131 for (unsigned int i = 0; i < layeridCount; ++i)
132 {
133 unsigned int layerid = layerids[i];
134 cout << "Removing notification for layer " << layerid << "\n";
135
136 ilmErrorTypes callResult = ilm_layerRemoveNotification(layerid);
137 if (ILM_SUCCESS != callResult)
138 {
139 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
140 cout << "Failed to remove notification callback of layer with ID " << layerid << "\n";
141 return;
142 }
143 }
144
145 if (layerids)
146 {
147 delete[] layerids;
148 }
149 }
150
surfaceNotificationCallback(t_ilm_layer surface,struct ilmSurfaceProperties * properties,t_ilm_notification_mask mask)151 void surfaceNotificationCallback(t_ilm_layer surface, struct ilmSurfaceProperties* properties, t_ilm_notification_mask mask)
152 {
153 cout << "\nNotification: surface " << surface << " updated properties:\n";
154
155 if (ILM_NOTIFICATION_VISIBILITY & mask)
156 {
157 cout << "\tvisibility = " << properties->visibility << "\n";
158 }
159
160 if (ILM_NOTIFICATION_OPACITY & mask)
161 {
162 cout << "\topacity = " << properties->opacity << "\n";
163 }
164
165 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
166 {
167 cout << "\tsource rect = x:" << properties->sourceX
168 << ", y:" << properties->sourceY
169 << ", width:" << properties->sourceWidth
170 << ", height:" << properties->sourceHeight
171 << "\n";
172 }
173
174 if (ILM_NOTIFICATION_DEST_RECT & mask)
175 {
176 cout << "\tdest rect = x:" << properties->destX
177 << ", y:" << properties->destY
178 << ", width:" << properties->destWidth
179 << ", height:" << properties->destHeight
180 << "\n";
181 }
182 }
183
watchSurface(unsigned int * surfaceids,unsigned int surfaceidCount)184 void watchSurface(unsigned int* surfaceids, unsigned int surfaceidCount)
185 {
186 for (unsigned int i = 0; i < surfaceidCount; ++i)
187 {
188 unsigned int surfaceid = surfaceids[i];
189 cout << "Setup notification for surface " << surfaceid << "\n";
190
191 ilmErrorTypes callResult = ilm_surfaceAddNotification(surfaceid, surfaceNotificationCallback);
192 if (ILM_SUCCESS != callResult)
193 {
194 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
195 cout << "Failed to add notification callback to surface with ID " << surfaceid << "\n";
196 return;
197 }
198 }
199
200 cout << "Waiting for notifications...\n";
201 int block;
202 cin >> block;
203
204 for (unsigned int i = 0; i < surfaceidCount; ++i)
205 {
206 unsigned int surfaceid = surfaceids[i];
207 cout << "Removing notification for surface " << surfaceid << "\n";
208
209 ilmErrorTypes callResult = ilm_surfaceRemoveNotification(surfaceid);
210 if (ILM_SUCCESS != callResult)
211 {
212 cout << "LayerManagerService returned: " << ILM_ERROR_STRING(callResult) << "\n";
213 cout << "Failed to remove notification callback of surface with ID " << surfaceid << "\n";
214 return;
215 }
216 }
217
218 if (surfaceids)
219 {
220 delete[] surfaceids;
221 }
222 }
223