1 /*
2 * Copyright (c) 2022-2024 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 #include "vibrator_infos.h"
16
17 #include "sensors_errors.h"
18
19 #undef LOG_TAG
20 #define LOG_TAG "MiscdeviceVibratorInfos"
21
22 namespace OHOS {
23 namespace Sensors {
24 namespace {
25 constexpr int32_t MAX_PATTERN_NUM = 1000;
26 } // namespace
27
Dump() const28 void VibratePattern::Dump() const
29 {
30 int32_t size = static_cast<int32_t>(events.size());
31 MISC_HILOGD("Pattern startTime:%{public}d, eventSize:%{public}d", startTime, size);
32 for (int32_t i = 0; i < size; ++i) {
33 std::string tag = (events[i].tag == EVENT_TAG_CONTINUOUS) ? "continuous" : "transient";
34 int32_t pointSize = static_cast<int32_t>(events[i].points.size());
35 MISC_HILOGD("Event tag:%{public}s, time:%{public}d, duration:%{public}d,"
36 "intensity:%{public}d, frequency:%{public}d, index:%{public}d, curve pointSize:%{public}d",
37 tag.c_str(), events[i].time, events[i].duration, events[i].intensity,
38 events[i].frequency, events[i].index, pointSize);
39 for (int32_t j = 0; j < pointSize; ++j) {
40 MISC_HILOGD("Curve point time:%{public}d, intensity:%{public}d, frequency:%{public}d",
41 events[i].points[j].time, events[i].points[j].intensity, events[i].points[j].frequency);
42 }
43 }
44 }
45
Dump() const46 void VibratePackage::Dump() const
47 {
48 int32_t size = static_cast<int32_t>(patterns.size());
49 MISC_HILOGD("Vibrate package pattern size:%{public}d", size);
50 for (int32_t i = 0; i < size; ++i) {
51 patterns[i].Dump();
52 }
53 }
54
Dump() const55 void VibratorCapacity::Dump() const
56 {
57 std::string isSupportHdHapticStr = isSupportHdHaptic ? "true" : "false";
58 std::string isSupportPresetMappingStr = isSupportPresetMapping ? "true" : "false";
59 std::string isSupportTimeDelayStr = isSupportTimeDelay ? "true" : "false";
60 MISC_HILOGD("SupportHdHaptic:%{public}s, SupportPresetMapping:%{public}s, "
61 "SupportTimeDelayStr:%{public}s", isSupportHdHapticStr.c_str(),
62 isSupportPresetMappingStr.c_str(), isSupportTimeDelayStr.c_str());
63 }
64
GetVibrateMode()65 int32_t VibratorCapacity::GetVibrateMode()
66 {
67 if (isSupportHdHaptic) {
68 return VIBRATE_MODE_HD;
69 }
70 if (isSupportPresetMapping) {
71 return VIBRATE_MODE_MAPPING;
72 }
73 if (isSupportTimeDelay) {
74 return VIBRATE_MODE_TIMES;
75 }
76 return -1;
77 }
78
Marshalling(Parcel & parcel) const79 bool VibratorCapacity::Marshalling(Parcel &parcel) const
80 {
81 if (!parcel.WriteBool(isSupportHdHaptic)) {
82 MISC_HILOGE("Write isSupportHdHaptic failed");
83 return false;
84 }
85 if (!parcel.WriteBool(isSupportPresetMapping)) {
86 MISC_HILOGE("Write isSupportPresetMapping failed");
87 return false;
88 }
89 if (!parcel.WriteBool(isSupportTimeDelay)) {
90 MISC_HILOGE("Write isSupportTimeDelay failed");
91 return false;
92 }
93 return true;
94 }
95
Unmarshalling(Parcel & data)96 VibratorCapacity* VibratorCapacity::Unmarshalling(Parcel &data)
97 {
98 auto capacity = new (std::nothrow) VibratorCapacity();
99 if (capacity == nullptr) {
100 MISC_HILOGE("Read init capacity failed");
101 return nullptr;
102 }
103 if (!(data.ReadBool(capacity->isSupportHdHaptic))) {
104 MISC_HILOGE("Read isSupportHdHaptic failed");
105 delete capacity;
106 capacity = nullptr;
107 return capacity;
108 }
109 if (!(data.ReadBool(capacity->isSupportPresetMapping))) {
110 MISC_HILOGE("Read isSupportPresetMapping failed");
111 delete capacity;
112 capacity = nullptr;
113 return capacity;
114 }
115 if (!(data.ReadBool(capacity->isSupportTimeDelay))) {
116 MISC_HILOGE("Read isSupportTimeDelay failed");
117 delete capacity;
118 capacity = nullptr;
119 return capacity;
120 }
121 return capacity;
122 }
123
Marshalling(Parcel & parcel) const124 bool VibratePattern::Marshalling(Parcel &parcel) const
125 {
126 if (!parcel.WriteInt32(startTime)) {
127 MISC_HILOGE("Write pattern's startTime failed");
128 return false;
129 }
130 if (!parcel.WriteInt32(patternDuration)) {
131 MISC_HILOGE("Write patternDuration failed");
132 return false;
133 }
134 if (!parcel.WriteInt32(static_cast<int32_t>(events.size()))) {
135 MISC_HILOGE("Write events's size failed");
136 return false;
137 }
138 for (size_t i = 0; i < events.size(); ++i) {
139 if (!parcel.WriteInt32(static_cast<int32_t>(events[i].tag))) {
140 MISC_HILOGE("Write tag failed");
141 return false;
142 }
143 if (!parcel.WriteInt32(events[i].time)) {
144 MISC_HILOGE("Write events's time failed");
145 return false;
146 }
147 if (!parcel.WriteInt32(events[i].duration)) {
148 MISC_HILOGE("Write duration failed");
149 return false;
150 }
151 if (!parcel.WriteInt32(events[i].intensity)) {
152 MISC_HILOGE("Write intensity failed");
153 return false;
154 }
155 if (!parcel.WriteInt32(events[i].frequency)) {
156 MISC_HILOGE("Write frequency failed");
157 return false;
158 }
159 if (!parcel.WriteInt32(events[i].index)) {
160 MISC_HILOGE("Write index failed");
161 return false;
162 }
163 if (!parcel.WriteInt32(static_cast<int32_t>(events[i].points.size()))) {
164 MISC_HILOGE("Write points's size failed");
165 return false;
166 }
167 for (size_t j = 0; j < events[i].points.size(); ++j) {
168 if (!parcel.WriteInt32(events[i].points[j].time)) {
169 MISC_HILOGE("Write points's time failed");
170 return false;
171 }
172 if (!parcel.WriteInt32(events[i].points[j].intensity)) {
173 MISC_HILOGE("Write points's intensity failed");
174 return false;
175 }
176 if (!parcel.WriteInt32(events[i].points[j].frequency)) {
177 MISC_HILOGE("Write points's frequency failed");
178 return false;
179 }
180 }
181 }
182 return true;
183 }
184
Unmarshalling(Parcel & data)185 VibratePattern* VibratePattern::Unmarshalling(Parcel &data)
186 {
187 auto pattern = new (std::nothrow) VibratePattern();
188 if (pattern == nullptr || !(data.ReadInt32(pattern->startTime)) || !(data.ReadInt32(pattern->patternDuration))) {
189 MISC_HILOGE("Read pattern basic info failed");
190 if (pattern != nullptr) {
191 delete pattern;
192 pattern = nullptr;
193 }
194 return pattern;
195 }
196 int32_t eventSize{ 0 };
197 if (!(data.ReadInt32(eventSize)) || eventSize > MAX_EVENT_SIZE) {
198 MISC_HILOGE("Read eventSize failed or eventSize exceed the maximum");
199 delete pattern;
200 pattern = nullptr;
201 return pattern;
202 }
203 for (int32_t i = 0; i < eventSize; ++i) {
204 VibrateEvent event;
205 int32_t tag{ -1 };
206 if (!data.ReadInt32(tag)) {
207 MISC_HILOGE("Read type failed");
208 delete pattern;
209 pattern = nullptr;
210 return pattern;
211 }
212 event.tag = static_cast<VibrateTag>(tag);
213 if (!data.ReadInt32(event.time) || !data.ReadInt32(event.duration) || !data.ReadInt32(event.intensity) ||
214 !data.ReadInt32(event.frequency) || !data.ReadInt32(event.index)) {
215 MISC_HILOGE("Read events info failed");
216 delete pattern;
217 pattern = nullptr;
218 return pattern;
219 }
220 int32_t pointSize{ 0 };
221 if (!data.ReadInt32(pointSize) || pointSize > MAX_POINT_SIZE) {
222 MISC_HILOGE("Read pointSize failed or pointSize exceed the maximum");
223 delete pattern;
224 pattern = nullptr;
225 return pattern;
226 }
227 pattern->events.emplace_back(event);
228 for (int32_t j = 0; j < pointSize; ++j) {
229 VibrateCurvePoint point;
230 if (!data.ReadInt32(point.time) || !data.ReadInt32(point.intensity) || !data.ReadInt32(point.frequency)) {
231 MISC_HILOGE("Read points info time failed");
232 delete pattern;
233 pattern = nullptr;
234 return pattern;
235 }
236 pattern->events[i].points.emplace_back(point);
237 }
238 }
239 return pattern;
240 }
241
Marshalling(Parcel & parcel) const242 bool VibratePackageIPC::Marshalling(Parcel &parcel) const
243 {
244 if (!parcel.WriteInt32(packageDuration)) {
245 MISC_HILOGE("Write packageDuration failed");
246 return false;
247 }
248 if (!parcel.WriteInt32(static_cast<int32_t>(patterns.size()))) {
249 MISC_HILOGE("Write pattern's patternNum failed");
250 return false;
251 }
252 for (size_t i = 0; i < patterns.size(); ++i) {
253 if (!parcel.WriteInt32(patterns[i].startTime)) {
254 MISC_HILOGE("Write pattern's startTime failed");
255 return false;
256 }
257 if (!parcel.WriteInt32(patterns[i].patternDuration)) {
258 MISC_HILOGE("Write patternDuration failed");
259 return false;
260 }
261 if (!parcel.WriteInt32(static_cast<int32_t>(patterns[i].events.size()))) {
262 MISC_HILOGE("Write events's size failed");
263 return false;
264 }
265 for (size_t j = 0; j < patterns[i].events.size(); ++j) {
266 if (!parcel.WriteInt32(static_cast<int32_t>(patterns[i].events[j].tag))) {
267 MISC_HILOGE("Write tag failed");
268 return false;
269 }
270 if (!parcel.WriteInt32(patterns[i].events[j].time)) {
271 MISC_HILOGE("Write events's time failed");
272 return false;
273 }
274 if (!parcel.WriteInt32(patterns[i].events[j].duration)) {
275 MISC_HILOGE("Write duration failed");
276 return false;
277 }
278 if (!parcel.WriteInt32(patterns[i].events[j].intensity)) {
279 MISC_HILOGE("Write intensity failed");
280 return false;
281 }
282 if (!parcel.WriteInt32(patterns[i].events[j].frequency)) {
283 MISC_HILOGE("Write frequency failed");
284 return false;
285 }
286 if (!parcel.WriteInt32(patterns[i].events[j].index)) {
287 MISC_HILOGE("Write index failed");
288 return false;
289 }
290 if (!parcel.WriteInt32(static_cast<int32_t>(patterns[i].events[j].points.size()))) {
291 MISC_HILOGE("Write points's size failed");
292 return false;
293 }
294 for (size_t k = 0; k < patterns[i].events[j].points.size(); ++k) {
295 if (!parcel.WriteInt32(patterns[i].events[j].points[k].time)) {
296 MISC_HILOGE("Write points's time failed");
297 return false;
298 }
299 if (!parcel.WriteInt32(patterns[i].events[j].points[k].intensity)) {
300 MISC_HILOGE("Write points's intensity failed");
301 return false;
302 }
303 if (!parcel.WriteInt32(patterns[i].events[j].points[k].frequency)) {
304 MISC_HILOGE("Write points's frequency failed");
305 return false;
306 }
307 }
308 }
309 }
310 return true;
311 }
312
Unmarshalling(Parcel & data)313 VibratePackageIPC* VibratePackageIPC::Unmarshalling(Parcel &data)
314 {
315 auto package = new (std::nothrow) VibratePackageIPC();
316 if (package == nullptr || !(data.ReadInt32(package->packageDuration))) {
317 MISC_HILOGE("Read pattern basic info failed");
318 if (package != nullptr) {
319 delete package;
320 package = nullptr;
321 }
322 return package;
323 }
324 int32_t patternNum{ 0 };
325 if (!data.ReadInt32(patternNum) || patternNum < 0 || patternNum > MAX_PATTERN_NUM) {
326 MISC_HILOGE("Read patternNum failed or patternNum exceed the maximum");
327 delete package;
328 package = nullptr;
329 return package;
330 }
331 for (int32_t i = 0; i < patternNum; ++i) {
332 VibratePattern pattern;
333 if (!data.ReadInt32(pattern.startTime)) {
334 MISC_HILOGE("Read pattern startTime failed");
335 delete package;
336 package = nullptr;
337 return package;
338 }
339 if (!data.ReadInt32(pattern.patternDuration)) {
340 MISC_HILOGE("Read pattern patternDuration failed");
341 delete package;
342 package = nullptr;
343 return package;
344 }
345 int32_t eventSize{ 0 };
346 if (!(data.ReadInt32(eventSize)) || eventSize > MAX_EVENT_SIZE || eventSize < 0) {
347 MISC_HILOGE("Read eventSize failed or eventSize exceed the maximum");
348 delete package;
349 package = nullptr;
350 return package;
351 }
352 for (int32_t j = 0; j < eventSize; ++j) {
353 VibrateEvent event;
354 int32_t tag{ -1 };
355 if (!data.ReadInt32(tag)) {
356 MISC_HILOGE("Read type failed");
357 delete package;
358 package = nullptr;
359 return package;
360 }
361 if (tag != VibrateTag::EVENT_TAG_CONTINUOUS && tag != VibrateTag::EVENT_TAG_TRANSIENT) {
362 MISC_HILOGE("Invalid tag value");
363 delete package;
364 package = nullptr;
365 return package;
366 }
367 event.tag = static_cast<VibrateTag>(tag);
368 if (!data.ReadInt32(event.time) || !data.ReadInt32(event.duration) || !data.ReadInt32(event.intensity) ||
369 !data.ReadInt32(event.frequency) || !data.ReadInt32(event.index)) {
370 MISC_HILOGE("Read events info failed");
371 delete package;
372 package = nullptr;
373 return package;
374 }
375 int32_t pointSize{ 0 };
376 if (!data.ReadInt32(pointSize) || pointSize > MAX_POINT_SIZE || pointSize < 0) {
377 MISC_HILOGE("Read pointSize failed or pointSize exceed the maximum");
378 delete package;
379 package = nullptr;
380 return package;
381 }
382 for (int32_t k = 0; k < pointSize; ++k) {
383 VibrateCurvePoint point;
384 if (!data.ReadInt32(point.time) || !data.ReadInt32(point.intensity) ||
385 !data.ReadInt32(point.frequency)) {
386 MISC_HILOGE("Read points info time failed");
387 delete package;
388 package = nullptr;
389 return package;
390 }
391 event.points.emplace_back(point);
392 }
393 pattern.events.emplace_back(event);
394 }
395 package->patterns.emplace_back(pattern);
396 }
397 return package;
398 }
399
Dump() const400 void VibratePackageIPC::Dump() const
401 {
402 int32_t size = static_cast<int32_t>(patterns.size());
403 MISC_HILOGD("Vibrate package pattern size:%{public}d", size);
404 for (int32_t i = 0; i < size; ++i) {
405 patterns[i].Dump();
406 }
407 }
408
Dump() const409 void VibrateParameter::Dump() const
410 {
411 MISC_HILOGI("intensity:%{public}d, frequency:%{public}d", intensity, frequency);
412 }
413
Marshalling(Parcel & parcel) const414 bool VibrateParameter::Marshalling(Parcel &parcel) const
415 {
416 if (!parcel.WriteInt32(intensity)) {
417 MISC_HILOGE("Write parameter's intensity failed");
418 return false;
419 }
420 if (!parcel.WriteInt32(frequency)) {
421 MISC_HILOGE("Write parameter's frequency failed");
422 return false;
423 }
424 return true;
425 }
426
Unmarshalling(Parcel & data)427 VibrateParameter* VibrateParameter::Unmarshalling(Parcel &data)
428 {
429 auto parameter = new (std::nothrow) VibrateParameter();
430 if (parameter == nullptr) {
431 MISC_HILOGE("Read init parameter failed");
432 return nullptr;
433 }
434 if (!(data.ReadInt32(parameter->intensity)) && !(data.ReadInt32(parameter->frequency))) {
435 MISC_HILOGE("Read parameter's intensity failed");
436 delete parameter;
437 parameter = nullptr;
438 }
439 return parameter;
440 }
441
Marshalling(Parcel & parcel) const442 bool VibratorInfoIPC::Marshalling(Parcel &parcel) const
443 {
444 if (!parcel.WriteInt32(deviceId)) {
445 MISC_HILOGE("Write deviceId failed");
446 return false;
447 }
448 if (!parcel.WriteInt32(vibratorId)) {
449 MISC_HILOGE("Write vibratorId failed");
450 return false;
451 }
452 if (!parcel.WriteString(deviceName)) {
453 MISC_HILOGE("Write deviceName failed");
454 return false;
455 }
456 if (!parcel.WriteBool(isSupportHdHaptic)) {
457 MISC_HILOGE("Write isSupportHdHaptic failed");
458 return false;
459 }
460 if (!parcel.WriteBool(isLocalVibrator)) {
461 MISC_HILOGE("Write isLocalVibrator failed");
462 return false;
463 }
464 return true;
465 }
466
Unmarshalling(Parcel & data)467 VibratorInfoIPC* VibratorInfoIPC::Unmarshalling(Parcel &data)
468 {
469 auto vibratorInfoIPC = new (std::nothrow) VibratorInfoIPC();
470 if (vibratorInfoIPC == nullptr) {
471 MISC_HILOGE("Read init vibratorInfoIPC failed");
472 return nullptr;
473 }
474 if (!data.ReadInt32(vibratorInfoIPC->deviceId)) {
475 MISC_HILOGE("Read deviceId failed");
476 delete vibratorInfoIPC;
477 vibratorInfoIPC = nullptr;
478 return vibratorInfoIPC;
479 }
480 if (!data.ReadInt32(vibratorInfoIPC->vibratorId)) {
481 MISC_HILOGE("Read vibratorId failed");
482 delete vibratorInfoIPC;
483 vibratorInfoIPC = nullptr;
484 return vibratorInfoIPC;
485 }
486 if (!data.ReadString(vibratorInfoIPC->deviceName)) {
487 MISC_HILOGE("Read deviceName failed");
488 delete vibratorInfoIPC;
489 vibratorInfoIPC = nullptr;
490 return vibratorInfoIPC;
491 }
492 if (!data.ReadBool(vibratorInfoIPC->isSupportHdHaptic)) {
493 MISC_HILOGE("Read isSupportHdHaptic failed");
494 delete vibratorInfoIPC;
495 vibratorInfoIPC = nullptr;
496 return vibratorInfoIPC;
497 }
498 if (!data.ReadBool(vibratorInfoIPC->isLocalVibrator)) {
499 MISC_HILOGE("Read isLocalVibrator failed");
500 delete vibratorInfoIPC;
501 vibratorInfoIPC = nullptr;
502 return vibratorInfoIPC;
503 }
504 return vibratorInfoIPC;
505 }
506
Dump() const507 void VibratorInfoIPC::Dump() const
508 {
509 std::string retStr = "";
510 retStr = "deviceId: "+ std::to_string(deviceId) + " ";
511 retStr += ("vibratorId: " + std::to_string(vibratorId) + " ");
512 retStr += ("deviceName: " + deviceName + " ");
513 retStr += ("isSupportHdHaptic: " + (isSupportHdHaptic? std::string("true"):std::string("false")) + " ");
514 MISC_HILOGI("VibratorInfoIPC: [%{public}s]", retStr.c_str());
515 }
516
Dump() const517 void VibratorIdentifierIPC::Dump() const
518 {
519 MISC_HILOGI("deviceId:%{public}d, vibratorId:%{public}d", deviceId, vibratorId);
520 }
521
Marshalling(Parcel & parcel) const522 bool VibratorIdentifierIPC::Marshalling(Parcel &parcel) const
523 {
524 if (!parcel.WriteInt32(deviceId)) {
525 MISC_HILOGE("Write parameter's deviceId failed");
526 return false;
527 }
528 if (!parcel.WriteInt32(vibratorId)) {
529 MISC_HILOGE("Write parameter's vibratorId failed");
530 return false;
531 }
532 return true;
533 }
534
Unmarshalling(Parcel & data)535 VibratorIdentifierIPC* VibratorIdentifierIPC::Unmarshalling(Parcel &data)
536 {
537 auto identifier = new (std::nothrow) VibratorIdentifierIPC();
538 if (identifier == nullptr) {
539 MISC_HILOGE("Read init parameter failed");
540 return nullptr;
541 }
542 if (!(data.ReadInt32(identifier->deviceId))) {
543 MISC_HILOGE("Read parameter's deviceId or vibratorId failed");
544 delete identifier;
545 identifier = nullptr;
546 return identifier;
547 }
548 if (!(data.ReadInt32(identifier->vibratorId))) {
549 MISC_HILOGE("Read parameter's deviceId or vibratorId failed");
550 delete identifier;
551 identifier = nullptr;
552 return identifier;
553 }
554 return identifier;
555 }
556
Marshalling(Parcel & parcel) const557 bool EffectInfoIPC::Marshalling(Parcel &parcel) const
558 {
559 if (!parcel.WriteInt32(duration)) {
560 MISC_HILOGE("Write duration failed");
561 return false;
562 }
563 if (!parcel.WriteBool(isSupportEffect)) {
564 MISC_HILOGE("Write isSupportEffect failed");
565 return false;
566 }
567 return true;
568 }
569
Unmarshalling(Parcel & data)570 EffectInfoIPC* EffectInfoIPC::Unmarshalling(Parcel &data)
571 {
572 auto effectInfoIPC = new (std::nothrow) EffectInfoIPC();
573 if (effectInfoIPC == nullptr) {
574 MISC_HILOGE("Read init EffectInfoIPC failed");
575 return nullptr;
576 }
577 if (!data.ReadInt32(effectInfoIPC->duration)) {
578 MISC_HILOGE("Read duration failed");
579 delete effectInfoIPC;
580 effectInfoIPC = nullptr;
581 return effectInfoIPC;
582 }
583 if (!data.ReadBool(effectInfoIPC->isSupportEffect)) {
584 MISC_HILOGE("Read isSupportEffect failed");
585 delete effectInfoIPC;
586 effectInfoIPC = nullptr;
587 return effectInfoIPC;
588 }
589 return effectInfoIPC;
590 }
591
Dump() const592 void EffectInfoIPC::Dump() const
593 {
594 std::string retStr = "";
595 retStr = "duration: "+ std::to_string(duration) + " ";
596 retStr += ("isSupportEffect: " + (isSupportEffect? std::string("true"):std::string("false")));
597 MISC_HILOGI("EffectInfoIPC: [%{public}s]", retStr.c_str());
598 }
599
Marshalling(Parcel & parcel) const600 bool CustomHapticInfoIPC::Marshalling(Parcel &parcel) const
601 {
602 if (!parcel.WriteInt32(usage)) {
603 MISC_HILOGE("Write usage failed");
604 return false;
605 }
606 if (!parcel.WriteBool(systemUsage)) {
607 MISC_HILOGE("Write systemUsage failed");
608 return false;
609 }
610 if (!parcel.WriteUint32(parameter.sessionId)) {
611 MISC_HILOGE("Write sessionId failed");
612 return false;
613 }
614 if (!parcel.WriteInt32(parameter.intensity)) {
615 MISC_HILOGE("Write intensity failed");
616 return false;
617 }
618 if (!parcel.WriteInt32(parameter.frequency)) {
619 MISC_HILOGE("Write frequency failed");
620 return false;
621 }
622 if (!parcel.WriteInt32(parameter.reserved)) {
623 MISC_HILOGE("Write reserved failed");
624 return false;
625 }
626 return true;
627 }
628
Unmarshalling(Parcel & data)629 CustomHapticInfoIPC* CustomHapticInfoIPC::Unmarshalling(Parcel &data)
630 {
631 auto customHapticInfoIPC = new (std::nothrow) CustomHapticInfoIPC();
632 if (customHapticInfoIPC == nullptr) {
633 MISC_HILOGE("Read init EffectInfoIPC failed");
634 return nullptr;
635 }
636 if (!data.ReadInt32(customHapticInfoIPC->usage)) {
637 MISC_HILOGE("Read usage failed");
638 delete customHapticInfoIPC;
639 customHapticInfoIPC = nullptr;
640 return customHapticInfoIPC;
641 }
642 if (!data.ReadBool(customHapticInfoIPC->systemUsage)) {
643 MISC_HILOGE("Read systemUsage failed");
644 delete customHapticInfoIPC;
645 customHapticInfoIPC = nullptr;
646 return customHapticInfoIPC;
647 }
648 if (!data.ReadUint32(customHapticInfoIPC->parameter.sessionId)) {
649 MISC_HILOGE("Read sessionId failed");
650 delete customHapticInfoIPC;
651 customHapticInfoIPC = nullptr;
652 return customHapticInfoIPC;
653 }
654 if (!data.ReadInt32(customHapticInfoIPC->parameter.intensity)) {
655 MISC_HILOGE("Read intensity failed");
656 delete customHapticInfoIPC;
657 customHapticInfoIPC = nullptr;
658 return customHapticInfoIPC;
659 }
660 if (!data.ReadInt32(customHapticInfoIPC->parameter.frequency)) {
661 MISC_HILOGE("Read frequency failed");
662 delete customHapticInfoIPC;
663 customHapticInfoIPC = nullptr;
664 return customHapticInfoIPC;
665 }
666 if (!data.ReadInt32(customHapticInfoIPC->parameter.reserved)) {
667 MISC_HILOGE("Read reserved failed");
668 delete customHapticInfoIPC;
669 customHapticInfoIPC = nullptr;
670 return customHapticInfoIPC;
671 }
672 return customHapticInfoIPC;
673 }
674
Dump() const675 void CustomHapticInfoIPC::Dump() const
676 {
677 std::string retStr = "";
678 retStr = "usage: "+ std::to_string(usage) + " ";
679 retStr += "systemUsage: " + std::to_string(systemUsage) + " ";
680 retStr += "parameter.intensity: " + std::to_string(parameter.intensity) + " ";
681 retStr += "parameter.frequency: " + std::to_string(parameter.frequency) + " ";
682 retStr += "parameter.reserved: " + std::to_string(parameter.reserved) + " ";
683 MISC_HILOGI("CustomHapticInfoIPC: [%{public}s]", retStr.c_str());
684 }
685
Marshalling(Parcel & parcel) const686 bool PrimitiveEffectIPC::Marshalling(Parcel &parcel) const
687 {
688 if (!parcel.WriteInt32(intensity)) {
689 MISC_HILOGE("Write intensity failed");
690 return false;
691 }
692 if (!parcel.WriteInt32(usage)) {
693 MISC_HILOGE("Write usage failed");
694 return false;
695 }
696 if (!parcel.WriteBool(systemUsage)) {
697 MISC_HILOGE("Write systemUsage failed");
698 return false;
699 }
700 if (!parcel.WriteInt32(count)) {
701 MISC_HILOGE("Write count failed");
702 return false;
703 }
704 return true;
705 }
706
Unmarshalling(Parcel & data)707 PrimitiveEffectIPC* PrimitiveEffectIPC::Unmarshalling(Parcel &data)
708 {
709 auto primitiveEffectIPC = new (std::nothrow) PrimitiveEffectIPC();
710 if (primitiveEffectIPC == nullptr) {
711 MISC_HILOGE("Read init PrimitiveEffectIPC failed");
712 return nullptr;
713 }
714 if (!data.ReadInt32(primitiveEffectIPC->intensity)) {
715 MISC_HILOGE("Read intensity failed");
716 delete primitiveEffectIPC;
717 primitiveEffectIPC = nullptr;
718 return primitiveEffectIPC;
719 }
720 if (!data.ReadInt32(primitiveEffectIPC->usage)) {
721 MISC_HILOGE("Read usage failed");
722 delete primitiveEffectIPC;
723 primitiveEffectIPC = nullptr;
724 return primitiveEffectIPC;
725 }
726
727 if (!data.ReadBool(primitiveEffectIPC->systemUsage)) {
728 MISC_HILOGE("Read systemUsage failed");
729 delete primitiveEffectIPC;
730 primitiveEffectIPC = nullptr;
731 return primitiveEffectIPC;
732 }
733
734 if (!data.ReadInt32(primitiveEffectIPC->count)) {
735 MISC_HILOGE("Read count failed");
736 delete primitiveEffectIPC;
737 primitiveEffectIPC = nullptr;
738 return primitiveEffectIPC;
739 }
740 return primitiveEffectIPC;
741 }
742
Dump() const743 void PrimitiveEffectIPC::Dump() const
744 {
745 std::string retStr = "";
746 retStr = "intensity: "+ std::to_string(intensity) + " ";
747 retStr += "usage: " + std::to_string(usage) + " ";
748 retStr += "systemUsage: " + std::to_string(systemUsage) + " ";
749 retStr += "count: " + std::to_string(count) + " ";
750 MISC_HILOGI("PrimitiveEffectIPC: [%{public}s]", retStr.c_str());
751 }
752
753 } // namespace Sensors
754 } // namespace OHOS
755