added more documentation
[deb_libcec.git] / src / LibCecSharp / CecSharpTypes.h
CommitLineData
4ef3b314
LOK
1#pragma once
2/*
f9717bcc
LOK
3* This file is part of the libCEC(R) library.
4*
5* libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
6* libCEC(R) is an original work, containing original code.
7*
8* libCEC(R) is a trademark of Pulse-Eight Limited.
9*
10* This program is dual-licensed; you can redistribute it and/or modify
11* it under the terms of the GNU General Public License as published by
12* the Free Software Foundation; either version 2 of the License, or
13* (at your option) any later version.
14*
15* This program is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with this program; if not, write to the Free Software
22* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23*
24*
25* Alternatively, you can license this library under a commercial license,
26* please contact Pulse-Eight Licensing for more information.
27*
28* For more information contact:
29* Pulse-Eight Licensing <license@pulse-eight.com>
30* http://www.pulse-eight.com/
31* http://www.pulse-eight.net/
32*/
4ef3b314 33
dc6366e8 34#include "../lib/platform/threads/mutex.h"
4ef3b314
LOK
35#include <vcclr.h>
36#include <msclr/marshal.h>
37#include "../../include/cec.h"
dc6366e8 38#include <vector>
4ef3b314
LOK
39
40#using <System.dll>
41
42namespace CecSharp
43{
8438c41f
LOK
44 /// <summary>
45 /// The device type. For client applications, libCEC only supports RecordingDevice, PlaybackDevice or Tuner.
46 /// libCEC uses RecordingDevice by default.
47 /// </summary>
f9717bcc
LOK
48 public enum class CecDeviceType
49 {
8438c41f
LOK
50 /// <summary>
51 /// Television
52 /// </summary>
f9717bcc 53 Tv = 0,
8438c41f
LOK
54 /// <summary>
55 /// Recording device
56 /// </summary>
f9717bcc 57 RecordingDevice = 1,
8438c41f
LOK
58 /// <summary>
59 /// Reserved / do not use
60 /// </summary>
f9717bcc 61 Reserved = 2,
8438c41f
LOK
62 /// <summary>
63 /// Tuner
64 /// </summary>
f9717bcc 65 Tuner = 3,
8438c41f
LOK
66 /// <summary>
67 /// Playback device
68 /// </summary>
f9717bcc 69 PlaybackDevice = 4,
8438c41f
LOK
70 /// <summary>
71 /// Audio system / AVR
72 /// </summary>
f9717bcc
LOK
73 AudioSystem = 5
74 };
75
8438c41f
LOK
76 /// <summary>
77 /// Log level that can be used by the logging callback method to filter messages from libCEC.
78 /// </summary>
f9717bcc
LOK
79 public enum class CecLogLevel
80 {
8438c41f
LOK
81 /// <summary>
82 /// No logging
83 /// </summary>
f9717bcc 84 None = 0,
8438c41f
LOK
85 /// <summary>
86 /// libCEC encountered a serious problem, and couldn't complete an action.
87 /// </summary>
f9717bcc 88 Error = 1,
8438c41f
LOK
89 /// <summary>
90 /// libCEC warns that it encountered a problem, but recovered.
91 /// </summary>
f9717bcc 92 Warning = 2,
8438c41f
LOK
93 /// <summary>
94 /// libCEC informs the client about a CEC state change.
95 /// </summary>
f9717bcc 96 Notice = 4,
8438c41f
LOK
97 /// <summary>
98 /// Raw CEC data traffic
99 /// </summary>
f9717bcc 100 Traffic = 8,
8438c41f
LOK
101 /// <summary>
102 /// Debugging messages
103 /// </summary>
f9717bcc 104 Debug = 16,
8438c41f
LOK
105 /// <summary>
106 /// Display all messages
107 /// </summary>
f9717bcc
LOK
108 All = 31
109 };
110
8438c41f
LOK
111 /// <summary>
112 /// A logical address on the CEC bus
113 /// </summary>
f9717bcc
LOK
114 public enum class CecLogicalAddress
115 {
8438c41f
LOK
116 /// <summary>
117 /// Not a valid logical address
118 /// </summary>
119 Unknown = -1,
120 /// <summary>
121 /// Television
122 /// </summary>
f9717bcc 123 Tv = 0,
8438c41f
LOK
124 /// <summary>
125 /// Recording device 1
126 /// </summary>
f9717bcc 127 RecordingDevice1 = 1,
8438c41f
LOK
128 /// <summary>
129 /// Recording device 2
130 /// </summary>
f9717bcc 131 RecordingDevice2 = 2,
8438c41f
LOK
132 /// <summary>
133 /// Tuner 1
134 /// </summary>
f9717bcc 135 Tuner1 = 3,
8438c41f
LOK
136 /// <summary>
137 /// Playback device 1
138 /// </summary>
f9717bcc 139 PlaybackDevice1 = 4,
8438c41f
LOK
140 /// <summary>
141 /// Audio system / AVR
142 /// </summary>
f9717bcc 143 AudioSystem = 5,
8438c41f
LOK
144 /// <summary>
145 /// Tuner 2
146 /// </summary>
f9717bcc 147 Tuner2 = 6,
8438c41f
LOK
148 /// <summary>
149 /// Tuner 3
150 /// </summary>
f9717bcc 151 Tuner3 = 7,
8438c41f
LOK
152 /// <summary>
153 /// Playback device 2
154 /// </summary>
f9717bcc 155 PlaybackDevice2 = 8,
8438c41f
LOK
156 /// <summary>
157 /// Recording device 3
158 /// </summary>
f9717bcc 159 RecordingDevice3 = 9,
8438c41f
LOK
160 /// <summary>
161 /// Tuner 4
162 /// </summary>
f9717bcc 163 Tuner4 = 10,
8438c41f
LOK
164 /// <summary>
165 /// Playback device 3
166 /// </summary>
f9717bcc 167 PlaybackDevice3 = 11,
8438c41f
LOK
168 /// <summary>
169 /// Reserved address 1
170 /// </summary>
f9717bcc 171 Reserved1 = 12,
8438c41f
LOK
172 /// <summary>
173 /// Reserved address 2
174 /// </summary>
f9717bcc 175 Reserved2 = 13,
8438c41f
LOK
176 /// <summary>
177 /// Free to use
178 /// </summary>
f9717bcc 179 FreeUse = 14,
8438c41f
LOK
180 /// <summary>
181 /// Unregistered / new device
182 /// </summary>
f9717bcc 183 Unregistered = 15,
8438c41f
LOK
184 /// <summary>
185 /// Broadcast address
186 /// </summary>
f9717bcc
LOK
187 Broadcast = 15
188 };
189
8438c41f
LOK
190 /// <summary>
191 /// The type of alert when libCEC calls the CecAlert callback
192 /// </summary>
f9717bcc
LOK
193 public enum class CecAlert
194 {
8438c41f
LOK
195 /// <summary>
196 /// The device needs servicing. This is set when the firmware can be upgraded, or when a problem with the firmware is detected.
197 /// The latest firmware flash tool can be downloaded from http://packages.pulse-eight.net/
198 /// </summary>
f9717bcc
LOK
199 ServiceDevice = 1
200 };
201
8438c41f
LOK
202 /// <summary>
203 /// The type of parameter that is sent with the CecAlert callback
204 /// </summary>
f9717bcc
LOK
205 public enum class CecParameterType
206 {
8438c41f
LOK
207 /// <summary>
208 /// The parameter is a string
209 /// </summary>
f9717bcc
LOK
210 ParameterTypeString = 1
211 };
212
8438c41f
LOK
213 /// <summary>
214 /// A parameter for the CecAlert callback
215 /// </summary>
f9717bcc
LOK
216 public ref class CecParameter
217 {
218 public:
8438c41f
LOK
219 /// <summary>
220 /// Create a new parameter
221 /// </summary>
222 /// <param name="type">The type of this parameter.</param>
223 /// <param name="data">The value of this parameter.</param>
224 CecParameter(CecParameterType type, System::String ^ data)
f9717bcc
LOK
225 {
226 Type = type;
8438c41f 227 Data = data;
f9717bcc
LOK
228 }
229
8438c41f
LOK
230 /// <summary>
231 /// The type of this parameter
232 /// </summary>
f9717bcc 233 property CecParameterType Type;
8438c41f
LOK
234 /// <summary>
235 /// The value of this parameter
236 /// </summary>
f9717bcc
LOK
237 property System::String ^ Data;
238 };
239
8438c41f
LOK
240 /// <summary>
241 /// The power status of a CEC device
242 /// </summary>
f9717bcc
LOK
243 public enum class CecPowerStatus
244 {
8438c41f
LOK
245 /// <summary>
246 /// Powered on
247 /// </summary>
f9717bcc 248 On = 0x00,
8438c41f
LOK
249 /// <summary>
250 /// In standby mode
251 /// </summary>
f9717bcc 252 Standby = 0x01,
8438c41f
LOK
253 /// <summary>
254 /// In transition from standby to on
255 /// </summary>
f9717bcc 256 InTransitionStandbyToOn = 0x02,
8438c41f
LOK
257 /// <summary>
258 /// In transition from on to standby
259 /// </summary>
f9717bcc 260 InTransitionOnToStandby = 0x03,
8438c41f
LOK
261 /// <summary>
262 /// Unknown status
263 /// </summary>
f9717bcc
LOK
264 Unknown = 0x99
265 };
266
8438c41f
LOK
267 /// <summary>
268 /// The CEC version of a CEC device
269 /// </summary>
f9717bcc
LOK
270 public enum class CecVersion
271 {
8438c41f
LOK
272 /// <summary>
273 /// Unknown version
274 /// </summary>
f9717bcc 275 Unknown = 0x00,
8438c41f
LOK
276 /// <summary>
277 /// Version 1.2
278 /// </summary>
f9717bcc 279 V1_2 = 0x01,
8438c41f
LOK
280 /// <summary>
281 /// Version 1.2a
282 /// </summary>
f9717bcc 283 V1_2A = 0x02,
8438c41f
LOK
284 /// <summary>
285 /// Version 1.3
286 /// </summary>
f9717bcc 287 V1_3 = 0x03,
8438c41f
LOK
288 /// <summary>
289 /// Version 1.3a
290 /// </summary>
f9717bcc 291 V1_3A = 0x04,
8438c41f
LOK
292 /// <summary>
293 /// Version 1.4
294 /// </summary>
f9717bcc
LOK
295 V1_4 = 0x05
296 };
297
8438c41f
LOK
298 /// <summary>
299 /// Parameter for OSD string display, that controls how to display the string
300 /// </summary>
f9717bcc
LOK
301 public enum class CecDisplayControl
302 {
8438c41f
LOK
303 /// <summary>
304 /// Display for the default time
305 /// </summary>
f9717bcc 306 DisplayForDefaultTime = 0x00,
8438c41f
LOK
307 /// <summary>
308 /// Display until it is cleared by ClearPreviousMessage
309 /// </summary>
f9717bcc 310 DisplayUntilCleared = 0x40,
8438c41f
LOK
311 /// <summary>
312 /// Clear message displayed by DisplayUntilCleared
313 /// </summary>
f9717bcc 314 ClearPreviousMessage = 0x80,
8438c41f
LOK
315 /// <summary>
316 /// Reserved / do not use
317 /// </summary>
f9717bcc
LOK
318 ReservedForFutureUse = 0xC0
319 };
320
8438c41f
LOK
321 /// <summary>
322 /// The menu state of a CEC device
323 /// </summary>
f9717bcc
LOK
324 public enum class CecMenuState
325 {
8438c41f
LOK
326 /// <summary>
327 /// Menu active
328 /// </summary>
f9717bcc 329 Activated = 0,
8438c41f
LOK
330 /// <summary>
331 /// Menu not active
332 /// </summary>
f9717bcc
LOK
333 Deactivated = 1
334 };
335
8438c41f
LOK
336 /// <summary>
337 /// Deck control mode for playback and recording devices
338 /// </summary>
f9717bcc
LOK
339 public enum class CecDeckControlMode
340 {
8438c41f
LOK
341 /// <summary>
342 /// Skip forward / wind
343 /// </summary>
f9717bcc 344 SkipForwardWind = 1,
8438c41f
LOK
345 /// <summary>
346 /// Skip reverse / rewind
347 /// </summary>
f9717bcc 348 SkipReverseRewind = 2,
8438c41f
LOK
349 /// <summary>
350 /// Stop
351 /// </summary>
f9717bcc 352 Stop = 3,
8438c41f
LOK
353 /// <summary>
354 /// Eject
355 /// </summary>
f9717bcc
LOK
356 Eject = 4
357 };
358
8438c41f
LOK
359 /// <summary>
360 /// Deck status for playback and recording devices
361 /// </summary>
f9717bcc
LOK
362 public enum class CecDeckInfo
363 {
8438c41f
LOK
364 /// <summary>
365 /// Playing
366 /// </summary>
f9717bcc 367 Play = 0x11,
8438c41f
LOK
368 /// <summary>
369 /// Recording
370 /// </summary>
f9717bcc 371 Record = 0x12,
8438c41f
LOK
372 /// <summary>
373 /// Reverse
374 /// </summary>
f9717bcc 375 Reverse = 0x13,
8438c41f
LOK
376 /// <summary>
377 /// Showing still frame
378 /// </summary>
f9717bcc 379 Still = 0x14,
8438c41f
LOK
380 /// <summary>
381 /// Playing slow
382 /// </summary>
f9717bcc 383 Slow = 0x15,
8438c41f
LOK
384 /// <summary>
385 /// Playing slow reverse
386 /// </summary>
f9717bcc 387 SlowReverse = 0x16,
8438c41f
LOK
388 /// <summary>
389 /// Fast forward
390 /// </summary>
f9717bcc 391 FastForward = 0x17,
8438c41f
LOK
392 /// <summary>
393 /// Fast reverse
394 /// </summary>
f9717bcc 395 FastReverse = 0x18,
8438c41f
LOK
396 /// <summary>
397 /// No media detected
398 /// </summary>
f9717bcc 399 NoMedia = 0x19,
8438c41f
LOK
400 /// <summary>
401 /// Stop / not playing
402 /// </summary>
f9717bcc 403 Stop = 0x1A,
8438c41f
LOK
404 /// <summary>
405 /// Skip forward / wind
406 /// </summary>
f9717bcc 407 SkipForwardWind = 0x1B,
8438c41f
LOK
408 /// <summary>
409 /// Skip reverse / rewind
410 /// </summary>
f9717bcc 411 SkipReverseRewind = 0x1C,
8438c41f
LOK
412 /// <summary>
413 /// Index search forward
414 /// </summary>
f9717bcc 415 IndexSearchForward = 0x1D,
8438c41f
LOK
416 /// <summary>
417 /// Index search reverse
418 /// </summary>
f9717bcc 419 IndexSearchReverse = 0x1E,
8438c41f
LOK
420 /// <summary>
421 /// Other / unknown status
422 /// </summary>
f9717bcc
LOK
423 OtherStatus = 0x1F
424 };
425
8438c41f
LOK
426 /// <summary>
427 /// User control code, the key code when the user presses or releases a button on the remote.
428 /// Used by SendKeypress() and the CecKeyPress() callback.
429 /// </summary>
f9717bcc
LOK
430 public enum class CecUserControlCode
431 {
8438c41f
LOK
432 /// <summary>
433 /// Select / OK
434 /// </summary>
f9717bcc 435 Select = 0x00,
8438c41f
LOK
436 /// <summary>
437 /// Direction up
438 /// </summary>
f9717bcc 439 Up = 0x01,
8438c41f
LOK
440 /// <summary>
441 /// Direction down
442 /// </summary>
f9717bcc 443 Down = 0x02,
8438c41f
LOK
444 /// <summary>
445 /// Direction left
446 /// </summary>
f9717bcc 447 Left = 0x03,
8438c41f
LOK
448 /// <summary>
449 /// Direction right
450 /// </summary>
f9717bcc 451 Right = 0x04,
8438c41f
LOK
452 /// <summary>
453 /// Direction right + up
454 /// </summary>
f9717bcc 455 RightUp = 0x05,
8438c41f
LOK
456 /// <summary>
457 /// Direction right + down
458 /// </summary>
f9717bcc 459 RightDown = 0x06,
8438c41f
LOK
460 /// <summary>
461 /// Direction left + up
462 /// </summary>
f9717bcc 463 LeftUp = 0x07,
8438c41f
LOK
464 /// <summary>
465 /// Direction left + down
466 /// </summary>
f9717bcc 467 LeftDown = 0x08,
8438c41f
LOK
468 /// <summary>
469 /// Root menu
470 /// </summary>
f9717bcc 471 RootMenu = 0x09,
8438c41f
LOK
472 /// <summary>
473 /// Setup menu
474 /// </summary>
f9717bcc 475 SetupMenu = 0x0A,
8438c41f
LOK
476 /// <summary>
477 /// Contents menu
478 /// </summary>
f9717bcc 479 ContentsMenu = 0x0B,
8438c41f
LOK
480 /// <summary>
481 /// Favourite menu
482 /// </summary>
f9717bcc 483 FavoriteMenu = 0x0C,
8438c41f
LOK
484 /// <summary>
485 /// Exit / back
486 /// </summary>
f9717bcc 487 Exit = 0x0D,
8438c41f
LOK
488 /// <summary>
489 /// Number 0
490 /// </summary>
f9717bcc 491 Number0 = 0x20,
8438c41f
LOK
492 /// <summary>
493 /// Number 1
494 /// </summary>
f9717bcc 495 Number1 = 0x21,
8438c41f
LOK
496 /// <summary>
497 /// Number 2
498 /// </summary>
f9717bcc 499 Number2 = 0x22,
8438c41f
LOK
500 /// <summary>
501 /// Number 3
502 /// </summary>
f9717bcc 503 Number3 = 0x23,
8438c41f
LOK
504 /// <summary>
505 /// Number 4
506 /// </summary>
f9717bcc 507 Number4 = 0x24,
8438c41f
LOK
508 /// <summary>
509 /// Number 5
510 /// </summary>
f9717bcc 511 Number5 = 0x25,
8438c41f
LOK
512 /// <summary>
513 /// Number 6
514 /// </summary>
f9717bcc 515 Number6 = 0x26,
8438c41f
LOK
516 /// <summary>
517 /// Number 7
518 /// </summary>
f9717bcc 519 Number7 = 0x27,
8438c41f
LOK
520 /// <summary>
521 /// Number 8
522 /// </summary>
f9717bcc 523 Number8 = 0x28,
8438c41f
LOK
524 /// <summary>
525 /// Number 9
526 /// </summary>
f9717bcc 527 Number9 = 0x29,
8438c41f
LOK
528 /// <summary>
529 /// .
530 /// </summary>
f9717bcc 531 Dot = 0x2A,
8438c41f
LOK
532 /// <summary>
533 /// Enter input
534 /// </summary>
f9717bcc 535 Enter = 0x2B,
8438c41f
LOK
536 /// <summary>
537 /// Clear input
538 /// </summary>
f9717bcc 539 Clear = 0x2C,
8438c41f
LOK
540 /// <summary>
541 /// Next favourite
542 /// </summary>
f9717bcc 543 NextFavorite = 0x2F,
8438c41f
LOK
544 /// <summary>
545 /// Channel up
546 /// </summary>
f9717bcc 547 ChannelUp = 0x30,
8438c41f
LOK
548 /// <summary>
549 /// Channel down
550 /// </summary>
f9717bcc 551 ChannelDown = 0x31,
8438c41f
LOK
552 /// <summary>
553 /// Previous channel
554 /// </summary>
f9717bcc 555 PreviousChannel = 0x32,
8438c41f
LOK
556 /// <summary>
557 /// Select sound track
558 /// </summary>
f9717bcc 559 SoundSelect = 0x33,
8438c41f
LOK
560 /// <summary>
561 /// Select input
562 /// </summary>
f9717bcc 563 InputSelect = 0x34,
8438c41f
LOK
564 /// <summary>
565 /// Display information
566 /// </summary>
f9717bcc 567 DisplayInformation = 0x35,
8438c41f
LOK
568 /// <summary>
569 /// Show help
570 /// </summary>
f9717bcc 571 Help = 0x36,
8438c41f
LOK
572 /// <summary>
573 /// Page up
574 /// </summary>
f9717bcc 575 PageUp = 0x37,
8438c41f
LOK
576 /// <summary>
577 /// Page down
578 /// </summary>
f9717bcc 579 PageDown = 0x38,
8438c41f
LOK
580 /// <summary>
581 /// Toggle powered on / standby
582 /// </summary>
f9717bcc 583 Power = 0x40,
8438c41f
LOK
584 /// <summary>
585 /// Volume up
586 /// </summary>
f9717bcc 587 VolumeUp = 0x41,
8438c41f
LOK
588 /// <summary>
589 /// Volume down
590 /// </summary>
f9717bcc 591 VolumeDown = 0x42,
8438c41f
LOK
592 /// <summary>
593 /// Mute audio
594 /// </summary>
f9717bcc 595 Mute = 0x43,
8438c41f
LOK
596 /// <summary>
597 /// Start playback
598 /// </summary>
f9717bcc 599 Play = 0x44,
8438c41f
LOK
600 /// <summary>
601 /// Stop playback
602 /// </summary>
f9717bcc 603 Stop = 0x45,
8438c41f
LOK
604 /// <summary>
605 /// Pause playback
606 /// </summary>
f9717bcc 607 Pause = 0x46,
8438c41f
LOK
608 /// <summary>
609 /// Toggle recording
610 /// </summary>
f9717bcc 611 Record = 0x47,
8438c41f
LOK
612 /// <summary>
613 /// Rewind
614 /// </summary>
f9717bcc 615 Rewind = 0x48,
8438c41f
LOK
616 /// <summary>
617 /// Fast forward
618 /// </summary>
f9717bcc 619 FastForward = 0x49,
8438c41f
LOK
620 /// <summary>
621 /// Eject media
622 /// </summary>
f9717bcc 623 Eject = 0x4A,
8438c41f
LOK
624 /// <summary>
625 /// Forward
626 /// </summary>
f9717bcc 627 Forward = 0x4B,
8438c41f
LOK
628 /// <summary>
629 /// Backward
630 /// </summary>
f9717bcc 631 Backward = 0x4C,
8438c41f
LOK
632 /// <summary>
633 /// Stop recording
634 /// </summary>
f9717bcc 635 StopRecord = 0x4D,
8438c41f
LOK
636 /// <summary>
637 /// Pause recording
638 /// </summary>
f9717bcc 639 PauseRecord = 0x4E,
8438c41f
LOK
640 /// <summary>
641 /// Change angle
642 /// </summary>
f9717bcc 643 Angle = 0x50,
8438c41f
LOK
644 /// <summary>
645 /// Toggle sub picture
646 /// </summary>
f9717bcc 647 SubPicture = 0x51,
8438c41f
LOK
648 /// <summary>
649 /// Toggle video on demand
650 /// </summary>
f9717bcc 651 VideoOnDemand = 0x52,
8438c41f
LOK
652 /// <summary>
653 /// Toggle electronic program guide (EPG)
654 /// </summary>
f9717bcc 655 ElectronicProgramGuide = 0x53,
8438c41f
LOK
656 /// <summary>
657 /// Toggle timer programming
658 /// </summary>
f9717bcc 659 TimerProgramming = 0x54,
8438c41f
LOK
660 /// <summary>
661 /// Set initial configuration
662 /// </summary>
f9717bcc 663 InitialConfiguration = 0x55,
8438c41f
LOK
664 /// <summary>
665 /// Start playback function
666 /// </summary>
f9717bcc 667 PlayFunction = 0x60,
8438c41f
LOK
668 /// <summary>
669 /// Pause playback function
670 /// </summary>
f9717bcc 671 PausePlayFunction = 0x61,
8438c41f
LOK
672 /// <summary>
673 /// Toggle recording function
674 /// </summary>
f9717bcc 675 RecordFunction = 0x62,
8438c41f
LOK
676 /// <summary>
677 /// Pause recording function
678 /// </summary>
f9717bcc 679 PauseRecordFunction = 0x63,
8438c41f
LOK
680 /// <summary>
681 /// Stop playback function
682 /// </summary>
f9717bcc 683 StopFunction = 0x64,
8438c41f
LOK
684 /// <summary>
685 /// Mute audio function
686 /// </summary>
f9717bcc 687 MuteFunction = 0x65,
8438c41f
LOK
688 /// <summary>
689 /// Restore volume function
690 /// </summary>
f9717bcc 691 RestoreVolumeFunction = 0x66,
8438c41f
LOK
692 /// <summary>
693 /// Tune function
694 /// </summary>
f9717bcc 695 TuneFunction = 0x67,
8438c41f
LOK
696 /// <summary>
697 /// Select media function
698 /// </summary>
f9717bcc 699 SelectMediaFunction = 0x68,
8438c41f
LOK
700 /// <summary>
701 /// Select AV input function
702 /// </summary>
f9717bcc 703 SelectAVInputFunction = 0x69,
8438c41f
LOK
704 /// <summary>
705 /// Select audio input function
706 /// </summary>
f9717bcc 707 SelectAudioInputFunction = 0x6A,
8438c41f
LOK
708 /// <summary>
709 /// Toggle powered on / standby function
710 /// </summary>
f9717bcc 711 PowerToggleFunction = 0x6B,
8438c41f
LOK
712 /// <summary>
713 /// Power off function
714 /// </summary>
f9717bcc 715 PowerOffFunction = 0x6C,
8438c41f
LOK
716 /// <summary>
717 /// Power on function
718 /// </summary>
f9717bcc 719 PowerOnFunction = 0x6D,
8438c41f
LOK
720 /// <summary>
721 /// F1 / blue button
722 /// </summary>
f9717bcc 723 F1Blue = 0x71,
8438c41f
LOK
724 /// <summary>
725 /// F2 / red button
726 /// </summary>
f9717bcc 727 F2Red = 0X72,
8438c41f
LOK
728 /// <summary>
729 /// F3 / green button
730 /// </summary>
f9717bcc 731 F3Green = 0x73,
8438c41f
LOK
732 /// <summary>
733 /// F4 / yellow button
734 /// </summary>
f9717bcc 735 F4Yellow = 0x74,
8438c41f
LOK
736 /// <summary>
737 /// F5
738 /// </summary>
f9717bcc 739 F5 = 0x75,
8438c41f
LOK
740 /// <summary>
741 /// Data / teletext
742 /// </summary>
f9717bcc 743 Data = 0x76,
8438c41f
LOK
744 /// <summary>
745 /// Max. valid key code for standard buttons
746 /// </summary>
f9717bcc 747 Max = 0x76,
8438c41f
LOK
748 /// <summary>
749 /// Extra return button on Samsung remotes
750 /// </summary>
f9717bcc 751 SamsungReturn = 0x91,
8438c41f
LOK
752 /// <summary>
753 /// Unknown / invalid key code
754 /// </summary>
f9717bcc
LOK
755 Unknown
756 };
757
8438c41f
LOK
758 /// <summary>
759 /// Vendor IDs for CEC devices
760 /// </summary>
f9717bcc
LOK
761 public enum class CecVendorId
762 {
763 Samsung = 0x0000F0,
764 LG = 0x00E091,
765 Panasonic = 0x008045,
766 Pioneer = 0x00E036,
767 Onkyo = 0x0009B0,
768 Yamaha = 0x00A0DE,
769 Philips = 0x00903E,
770 Sony = 0x080046,
771 Toshiba = 0x000039,
772 Akai = 0x0020C7,
773 Benq = 0x8065E9,
774 Daewoo = 0x009053,
775 Grundig = 0x00D0D5,
776 Medion = 0x000CB8,
777 Sharp = 0x08001F,
778 Vizio = 0x6B746D,
779 Unknown = 0
780 };
781
8438c41f
LOK
782 /// <summary>
783 /// Audio status of audio system / AVR devices
784 /// </summary>
f9717bcc
LOK
785 public enum class CecAudioStatus
786 {
8438c41f
LOK
787 /// <summary>
788 /// Muted
789 /// </summary>
f9717bcc 790 MuteStatusMask = 0x80,
8438c41f
LOK
791 /// <summary>
792 /// Not muted, volume status mask
793 /// </summary>
f9717bcc 794 VolumeStatusMask = 0x7F,
8438c41f
LOK
795 /// <summary>
796 /// Minumum volume
797 /// </summary>
f9717bcc 798 VolumeMin = 0x00,
8438c41f
LOK
799 /// <summary>
800 /// Maximum volume
801 /// </summary>
f9717bcc 802 VolumeMax = 0x64,
8438c41f
LOK
803 /// <summary>
804 /// Unknown status
805 /// </summary>
f9717bcc
LOK
806 VolumeStatusUnknown = 0x7F
807 };
808
8438c41f
LOK
809 /// <summary>
810 /// CEC opcodes, as described in the HDMI CEC specification
811 /// </summary>
f9717bcc
LOK
812 public enum class CecOpcode
813 {
8438c41f
LOK
814 /// <summary>
815 /// Active source
816 /// </summary>
f9717bcc 817 ActiveSource = 0x82,
8438c41f
LOK
818 /// <summary>
819 /// Image view on: power on display for image display
820 /// </summary>
f9717bcc 821 ImageViewOn = 0x04,
8438c41f
LOK
822 /// <summary>
823 /// Text view on: power on display for text display
824 /// </summary>
f9717bcc 825 TextViewOn = 0x0D,
8438c41f
LOK
826 /// <summary>
827 /// Device no longer is the active source
828 /// </summary>
f9717bcc 829 InactiveSource = 0x9D,
8438c41f
LOK
830 /// <summary>
831 /// Request which device has the active source status
832 /// </summary>
f9717bcc 833 RequestActiveSource = 0x85,
8438c41f
LOK
834 /// <summary>
835 /// Routing change for HDMI switches
836 /// </summary>
f9717bcc 837 RoutingChange = 0x80,
8438c41f
LOK
838 /// <summary>
839 /// Routing information for HDMI switches
840 /// </summary>
f9717bcc 841 RoutingInformation = 0x81,
8438c41f
LOK
842 /// <summary>
843 /// Change the stream path to the given physical address
844 /// </summary>
f9717bcc 845 SetStreamPath = 0x86,
8438c41f
LOK
846 /// <summary>
847 /// Inform that a device went into standby mode
848 /// </summary>
f9717bcc 849 Standby = 0x36,
8438c41f
LOK
850 /// <summary>
851 /// Stop recording
852 /// </summary>
f9717bcc 853 RecordOff = 0x0B,
8438c41f
LOK
854 /// <summary>
855 /// Start recording
856 /// </summary>
f9717bcc 857 RecordOn = 0x09,
8438c41f
LOK
858 /// <summary>
859 /// Recording status information
860 /// </summary>
f9717bcc 861 RecordStatus = 0x0A,
8438c41f
LOK
862 /// <summary>
863 /// Record current display
864 /// </summary>
f9717bcc 865 RecordTvScreen = 0x0F,
8438c41f
LOK
866 /// <summary>
867 /// Clear analogue timer
868 /// </summary>
f9717bcc 869 ClearAnalogueTimer = 0x33,
8438c41f
LOK
870 /// <summary>
871 /// Clear digital timer
872 /// </summary>
f9717bcc 873 ClearDigitalTimer = 0x99,
8438c41f
LOK
874 /// <summary>
875 /// Clear external timer
876 /// </summary>
f9717bcc 877 ClearExternalTimer = 0xA1,
8438c41f
LOK
878 /// <summary>
879 /// Set analogue timer
880 /// </summary>
f9717bcc 881 SetAnalogueTimer = 0x34,
8438c41f
LOK
882 /// <summary>
883 /// Set digital timer
884 /// </summary>
f9717bcc 885 SetDigitalTimer = 0x97,
8438c41f
LOK
886 /// <summary>
887 /// Set external timer
888 /// </summary>
f9717bcc 889 SetExternalTimer = 0xA2,
8438c41f
LOK
890 /// <summary>
891 /// Set program title of a timer
892 /// </summary>
f9717bcc 893 SetTimerProgramTitle = 0x67,
8438c41f
LOK
894 /// <summary>
895 /// Timer status cleared
896 /// </summary>
f9717bcc 897 TimerClearedStatus = 0x43,
8438c41f
LOK
898 /// <summary>
899 /// Timer status information
900 /// </summary>
f9717bcc 901 TimerStatus = 0x35,
8438c41f
LOK
902 /// <summary>
903 /// CEC version used by a device
904 /// </summary>
f9717bcc 905 CecVersion = 0x9E,
8438c41f
LOK
906 /// <summary>
907 /// Request CEC version of a device
908 /// </summary>
f9717bcc 909 GetCecVersion = 0x9F,
8438c41f
LOK
910 /// <summary>
911 /// Request physical address of a device
912 /// </summary>
f9717bcc 913 GivePhysicalAddress = 0x83,
8438c41f
LOK
914 /// <summary>
915 /// Request language code of the menu language of a device
916 /// </summary>
f9717bcc 917 GetMenuLanguage = 0x91,
8438c41f
LOK
918 /// <summary>
919 /// Report the physical address
920 /// </summary>
f9717bcc 921 ReportPhysicalAddress = 0x84,
8438c41f
LOK
922 /// <summary>
923 /// Report the language code of the menu language
924 /// </summary>
f9717bcc 925 SetMenuLanguage = 0x32,
8438c41f
LOK
926 /// <summary>
927 /// Deck control for playback and recording devices
928 /// </summary>
f9717bcc 929 DeckControl = 0x42,
8438c41f
LOK
930 /// <summary>
931 /// Deck status for playback and recording devices
932 /// </summary>
f9717bcc 933 DeckStatus = 0x1B,
8438c41f
LOK
934 /// <summary>
935 /// Request deck status from playback and recording devices
936 /// </summary>
f9717bcc 937 GiveDeckStatus = 0x1A,
8438c41f
LOK
938 /// <summary>
939 /// Start playback on playback and recording devices
940 /// </summary>
f9717bcc 941 Play = 0x41,
8438c41f
LOK
942 /// <summary>
943 /// Request tuner status
944 /// </summary>
f9717bcc 945 GiveTunerDeviceStatus = 0x08,
8438c41f
LOK
946 /// <summary>
947 /// Select analogue service on a tuner
948 /// </summary>
f9717bcc 949 SelectAnalogueService = 0x92,
8438c41f
LOK
950 /// <summary>
951 /// Select digital service on a tuner
952 /// </summary>
f9717bcc 953 SelectDigtalService = 0x93,
8438c41f
LOK
954 /// <summary>
955 /// Report tuner device status
956 /// </summary>
f9717bcc 957 TunerDeviceStatus = 0x07,
8438c41f
LOK
958 /// <summary>
959 /// Tuner step decrement
960 /// </summary>
f9717bcc 961 TunerStepDecrement = 0x06,
8438c41f
LOK
962 /// <summary>
963 /// Tuner step increment
964 /// </summary>
f9717bcc 965 TunerStepIncrement = 0x05,
8438c41f
LOK
966 /// <summary>
967 /// Report device vendor ID
968 /// </summary>
f9717bcc 969 DeviceVendorId = 0x87,
8438c41f
LOK
970 /// <summary>
971 /// Request device vendor ID
972 /// </summary>
f9717bcc 973 GiveDeviceVendorId = 0x8C,
8438c41f
LOK
974 /// <summary>
975 /// Vendor specific command
976 /// </summary>
f9717bcc 977 VendorCommand = 0x89,
8438c41f
LOK
978 /// <summary>
979 /// Vendor specific command with vendor ID
980 /// </summary>
f9717bcc 981 VendorCommandWithId = 0xA0,
8438c41f
LOK
982 /// <summary>
983 /// Vendor specific remote button pressed
984 /// </summary>
f9717bcc 985 VendorRemoteButtonDown = 0x8A,
8438c41f
LOK
986 /// <summary>
987 /// Vendor specific remote button released
988 /// </summary>
f9717bcc 989 VendorRemoteButtonUp = 0x8B,
8438c41f
LOK
990 /// <summary>
991 /// Display / clear OSD string
992 /// </summary>
f9717bcc 993 SetOsdString = 0x64,
8438c41f
LOK
994 /// <summary>
995 /// Request device OSD name
996 /// </summary>
f9717bcc 997 GiveOsdName = 0x46,
8438c41f
LOK
998 /// <summary>
999 /// Report device OSD name
1000 /// </summary>
f9717bcc 1001 SetOsdName = 0x47,
8438c41f
LOK
1002 /// <summary>
1003 /// Request device menu status
1004 /// </summary>
f9717bcc 1005 MenuRequest = 0x8D,
8438c41f
LOK
1006 /// <summary>
1007 /// Report device menu status
1008 /// </summary>
f9717bcc 1009 MenuStatus = 0x8E,
8438c41f
LOK
1010 /// <summary>
1011 /// Remote button pressed
1012 /// </summary>
f9717bcc 1013 UserControlPressed = 0x44,
8438c41f
LOK
1014 /// <summary>
1015 /// Remote button released
1016 /// </summary>
f9717bcc 1017 UserControlRelease = 0x45,
8438c41f
LOK
1018 /// <summary>
1019 /// Request device power status
1020 /// </summary>
f9717bcc 1021 GiveDevicePowerStatus = 0x8F,
8438c41f
LOK
1022 /// <summary>
1023 /// Report device power status
1024 /// </summary>
f9717bcc 1025 ReportPowerStatus = 0x90,
8438c41f
LOK
1026 /// <summary>
1027 /// Feature abort / unsupported command
1028 /// </summary>
f9717bcc 1029 FeatureAbort = 0x00,
8438c41f
LOK
1030 /// <summary>
1031 /// Abort command
1032 /// </summary>
f9717bcc 1033 Abort = 0xFF,
8438c41f
LOK
1034 /// <summary>
1035 /// Give audio status
1036 /// </summary>
f9717bcc 1037 GiveAudioStatus = 0x71,
8438c41f
LOK
1038 /// <summary>
1039 /// Give audiosystem mode
1040 /// </summary>
f9717bcc 1041 GiveSystemAudioMode = 0x7D,
8438c41f
LOK
1042 /// <summary>
1043 /// Report device audio status
1044 /// </summary>
f9717bcc 1045 ReportAudioStatus = 0x7A,
8438c41f
LOK
1046 /// <summary>
1047 /// Set audiosystem mode
1048 /// </summary>
f9717bcc 1049 SetSystemAudioMode = 0x72,
8438c41f
LOK
1050 /// <summary>
1051 /// Request audiosystem mode
1052 /// </summary>
f9717bcc 1053 SystemAudioModeRequest = 0x70,
8438c41f
LOK
1054 /// <summary>
1055 /// Report audiosystem mode
1056 /// </summary>
f9717bcc 1057 SystemAudioModeStatus = 0x7E,
8438c41f
LOK
1058 /// <summary>
1059 /// Set audio bitrate
1060 /// </summary>
f9717bcc 1061 SetAudioRate = 0x9A,
8438c41f
LOK
1062 /// <summary>
1063 /// When this opcode is set, no opcode will be sent to the device / poll message
1064 /// This is one of the reserved numbers
1065 /// </summary>
f9717bcc
LOK
1066 None = 0xFD
1067 };
1068
8438c41f
LOK
1069 /// <summary>
1070 /// Audiosystem status
1071 /// </summary>
f9717bcc
LOK
1072 public enum class CecSystemAudioStatus
1073 {
8438c41f
LOK
1074 /// <summary>
1075 /// Turned off
1076 /// </summary>
f9717bcc 1077 Off = 0,
8438c41f
LOK
1078 /// <summary>
1079 /// Turned on
1080 /// </summary>
f9717bcc
LOK
1081 On = 1
1082 };
1083
8438c41f
LOK
1084 /// <summary>
1085 /// libCEC client application version
1086 /// </summary>
f9717bcc
LOK
1087 public enum class CecClientVersion
1088 {
8438c41f
LOK
1089 /// <summary>
1090 /// before v1.5.0
1091 /// </summary>
f9717bcc 1092 VersionPre1_5 = 0,
8438c41f
LOK
1093 /// <summary>
1094 /// v1.5.0
1095 /// </summary>
f9717bcc 1096 Version1_5_0 = 0x1500,
8438c41f
LOK
1097 /// <summary>
1098 /// v1.5.1
1099 /// </summary>
f9717bcc 1100 Version1_5_1 = 0x1501,
8438c41f
LOK
1101 /// <summary>
1102 /// v1.5.2
1103 /// </summary>
f9717bcc 1104 Version1_5_2 = 0x1502,
8438c41f
LOK
1105 /// <summary>
1106 /// v1.5.3
1107 /// </summary>
f9717bcc 1108 Version1_5_3 = 0x1503,
8438c41f
LOK
1109 /// <summary>
1110 /// v1.6.0
1111 /// </summary>
f9717bcc 1112 Version1_6_0 = 0x1600,
8438c41f
LOK
1113 /// <summary>
1114 /// v1.6.1
1115 /// </summary>
f9717bcc 1116 Version1_6_1 = 0x1601,
8438c41f
LOK
1117 /// <summary>
1118 /// v1.6.2
1119 /// </summary>
f9717bcc 1120 Version1_6_2 = 0x1602,
8438c41f
LOK
1121 /// <summary>
1122 /// v1.6.3
1123 /// </summary>
f9717bcc 1124 Version1_6_3 = 0x1603,
8438c41f
LOK
1125 /// <summary>
1126 /// v1.7.0
1127 /// </summary>
f9717bcc 1128 Version1_7_0 = 0x1700,
8438c41f
LOK
1129 /// <summary>
1130 /// v1.7.1
1131 /// </summary>
f9717bcc 1132 Version1_7_1 = 0x1701,
8438c41f
LOK
1133 /// <summary>
1134 /// v1.7.2
1135 /// </summary>
f9717bcc 1136 Version1_7_2 = 0x1702,
8438c41f
LOK
1137 /// <summary>
1138 /// v1.8.0
1139 /// </summary>
f9717bcc 1140 Version1_8_0 = 0x1800,
8438c41f
LOK
1141 /// <summary>
1142 /// v1.8.1
1143 /// </summary>
f9717bcc 1144 Version1_8_1 = 0x1801,
8438c41f
LOK
1145 /// <summary>
1146 /// v1.8.2
1147 /// </summary>
f9717bcc 1148 Version1_8_2 = 0x1802,
8438c41f
LOK
1149 /// <summary>
1150 /// v1.9.0
1151 /// </summary>
f9717bcc
LOK
1152 Version1_9_0 = 0x1900
1153 };
1154
8438c41f
LOK
1155 /// <summary>
1156 /// libCEC version
1157 /// </summary>
f9717bcc
LOK
1158 public enum class CecServerVersion
1159 {
8438c41f
LOK
1160 /// <summary>
1161 /// before v1.5.0
1162 /// </summary>
f9717bcc 1163 VersionPre1_5 = 0,
8438c41f
LOK
1164 /// <summary>
1165 /// v1.5.0
1166 /// </summary>
f9717bcc 1167 Version1_5_0 = 0x1500,
8438c41f
LOK
1168 /// <summary>
1169 /// v1.5.1
1170 /// </summary>
f9717bcc 1171 Version1_5_1 = 0x1501,
8438c41f
LOK
1172 /// <summary>
1173 /// v1.5.2
1174 /// </summary>
f9717bcc 1175 Version1_5_2 = 0x1502,
8438c41f
LOK
1176 /// <summary>
1177 /// v1.5.3
1178 /// </summary>
f9717bcc 1179 Version1_5_3 = 0x1503,
8438c41f
LOK
1180 /// <summary>
1181 /// v1.6.0
1182 /// </summary>
f9717bcc 1183 Version1_6_0 = 0x1600,
8438c41f
LOK
1184 /// <summary>
1185 /// v1.6.1
1186 /// </summary>
f9717bcc 1187 Version1_6_1 = 0x1601,
8438c41f
LOK
1188 /// <summary>
1189 /// v1.6.2
1190 /// </summary>
f9717bcc 1191 Version1_6_2 = 0x1602,
8438c41f
LOK
1192 /// <summary>
1193 /// v1.6.3
1194 /// </summary>
f9717bcc 1195 Version1_6_3 = 0x1603,
8438c41f
LOK
1196 /// <summary>
1197 /// v1.7.0
1198 /// </summary>
f9717bcc 1199 Version1_7_0 = 0x1700,
8438c41f
LOK
1200 /// <summary>
1201 /// v1.7.1
1202 /// </summary>
f9717bcc 1203 Version1_7_1 = 0x1701,
8438c41f
LOK
1204 /// <summary>
1205 /// v1.7.2
1206 /// </summary>
f9717bcc 1207 Version1_7_2 = 0x1702,
8438c41f
LOK
1208 /// <summary>
1209 /// v1.8.0
1210 /// </summary>
f9717bcc 1211 Version1_8_0 = 0x1800,
8438c41f
LOK
1212 /// <summary>
1213 /// v1.8.1
1214 /// </summary>
f9717bcc 1215 Version1_8_1 = 0x1801,
8438c41f
LOK
1216 /// <summary>
1217 /// v1.8.2
1218 /// </summary>
f9717bcc 1219 Version1_8_2 = 0x1802,
8438c41f
LOK
1220 /// <summary>
1221 /// v1.9.0
1222 /// </summary>
f9717bcc
LOK
1223 Version1_9_0 = 0x1900
1224 };
1225
8438c41f
LOK
1226 /// <summary>
1227 /// Type of adapter to which libCEC is connected
1228 /// </summary>
22190f06
LOK
1229 public enum class CecAdapterType
1230 {
8438c41f
LOK
1231 /// <summary>
1232 /// Unknown adapter type
1233 /// </summary>
22190f06 1234 Unknown = 0,
8438c41f
LOK
1235 /// <summary>
1236 /// Pulse-Eight USB-CEC adapter
1237 /// </summary>
22190f06 1238 PulseEightExternal = 0x1,
8438c41f
LOK
1239 /// <summary>
1240 /// Pulse-Eight CEC daughterboard
1241 /// </summary>
22190f06 1242 PulseEightDaughterboard = 0x2,
8438c41f
LOK
1243 /// <summary>
1244 /// Raspberry Pi
1245 /// </summary>
22190f06
LOK
1246 RaspberryPi = 0x100
1247 };
1248
f9717bcc 1249 /// <summary>
8438c41f 1250 /// Descriptor of a CEC adapter, returned when scanning for adapters that are connected to the system
f9717bcc
LOK
1251 /// </summary>
1252 public ref class CecAdapter
1253 {
1254 public:
1255 /// <summary>
1256 /// Create a new CEC adapter descriptor
1257 /// </summary>
1258 /// <param name="path"> The path descriptor for this CEC adapter</param>
1259 /// <param name="comPort">The COM port of this CEC adapter</param>
1260 CecAdapter(System::String ^ path, System::String ^ comPort)
1261 {
1262 Path = path;
1263 ComPort = comPort;
1264 }
1265
1266 /// <summary>
1267 /// The path descriptor for this CEC adapter
1268 /// </summary>
1269 property System::String ^ Path;
1270
1271 /// <summary>
1272 /// The COM port of this CEC adapter
1273 /// </summary>
1274 property System::String ^ ComPort;
1275 };
1276
1277 /// <summary>
1278 /// A list of CEC device types
1279 /// </summary>
1280 public ref class CecDeviceTypeList
1281 {
1282 public:
1283 /// <summary>
1284 /// Create a new empty list of CEC device types
1285 /// </summary>
1286 CecDeviceTypeList(void)
1287 {
1288 Types = gcnew array<CecDeviceType>(5);
1289 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
1290 Types[iPtr] = CecDeviceType::Reserved;
1291 }
1292
1293 /// <summary>
1294 /// The array with CecDeviceType instances in this list.
1295 /// </summary>
1296 property array<CecDeviceType> ^ Types;
1297 };
1298
1299 /// <summary>
1300 /// A list of logical addresses
1301 /// </summary>
1302 public ref class CecLogicalAddresses
1303 {
1304 public:
1305 /// <summary>
1306 /// Create a new empty list of logical addresses
1307 /// </summary>
1308 CecLogicalAddresses(void)
1309 {
1310 Addresses = gcnew array<CecLogicalAddress>(16);
1311 Clear();
1312 }
1313
1314 /// <summary>
1315 /// Clears this list
1316 /// </summary>
1317 void Clear(void)
1318 {
1319 Primary = CecLogicalAddress::Unknown;
1320 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
1321 Addresses[iPtr] = CecLogicalAddress::Unknown;
1322 }
1323
1324 /// <summary>
1325 /// Checks whether a logical address is set in this list.
1326 /// </summary>
1327 /// <param name="address">The address to check.</param>
1328 /// <returns>True when set, false otherwise</returns>
1329 bool IsSet(CecLogicalAddress address)
1330 {
1331 return Addresses[(unsigned int)address] != CecLogicalAddress::Unknown;
1332 }
1333
1334 /// <summary>
1335 /// Add a logical address to this list (if it's not set already)
1336 /// </summary>
1337 /// <param name="address">The address to add.</param>
1338 void Set(CecLogicalAddress address)
1339 {
1340 Addresses[(unsigned int)address] = address;
1341 if (Primary == CecLogicalAddress::Unknown)
1342 Primary = address;
1343 }
1344
1345 /// <summary>
1346 /// The primary (first) address in this list
1347 /// </summary>
1348 property CecLogicalAddress Primary;
1349
1350 /// <summary>
1351 /// The list of addresses
1352 /// </summary>
1353 property array<CecLogicalAddress> ^ Addresses;
1354 };
1355
1356
1357 /// <summary>
1358 /// Byte array used for CEC command parameters
1359 /// </summary>
1360 public ref class CecDatapacket
1361 {
1362 public:
1363 /// <summary>
1364 /// Create a new byte array with maximum size 100
1365 /// </summary>
1366 CecDatapacket(void)
1367 {
1368 Data = gcnew array<uint8_t>(100);
1369 Size = 0;
1370 }
1371
1372 /// <summary>
1373 /// Adds a byte to this byte array
1374 /// </summary>
1375 /// <param name="data">The byte to add.</param>
1376 void PushBack(uint8_t data)
1377 {
1378 if (Size < 100)
1379 {
1380 Data[Size] = data;
1381 Size++;
1382 }
1383 }
1384
1385 /// <summary>
1386 /// Array data
1387 /// </summary>
1388 property array<uint8_t> ^ Data;
1389
1390 /// <summary>
1391 /// Current data size
1392 /// </summary>
1393 property uint8_t Size;
1394 };
1395
1396 /// <summary>
1397 /// A CEC command that is received or transmitted over the CEC bus
1398 /// </summary>
1399 public ref class CecCommand
1400 {
1401 public:
1402 /// <summary>
1403 /// Create a new CEC command instance
1404 /// </summary>
1405 /// <param name="initiator">The initiator of the command</param>
1406 /// <param name="destination">The receiver of the command</param>
1407 /// <param name="ack">True when the ack bit is set, false otherwise</param>
1408 /// <param name="eom">True when the eom bit is set, false otherwise</param>
1409 /// <param name="opcode">The CEC opcode of this command</param>
1410 /// <param name="transmitTimeout">The timeout to use when transmitting a command</param>
1411 CecCommand(CecLogicalAddress initiator, CecLogicalAddress destination, bool ack, bool eom, CecOpcode opcode, int32_t transmitTimeout)
1412 {
1413 Initiator = initiator;
1414 Destination = destination;
1415 Ack = ack;
1416 Eom = eom;
1417 Opcode = opcode;
1418 OpcodeSet = true;
1419 TransmitTimeout = transmitTimeout;
1420 Parameters = gcnew CecDatapacket;
1421 Empty = false;
1422 }
1423
1424 /// <summary>
1425 /// Create a new empty CEC command instance
1426 /// </summary>
1427 CecCommand(void)
1428 {
1429 Initiator = CecLogicalAddress::Unknown;
1430 Destination = CecLogicalAddress::Unknown;
1431 Ack = false;
1432 Eom = false;
1433 Opcode = CecOpcode::None;
1434 OpcodeSet = false;
1435 TransmitTimeout = 0;
1436 Parameters = gcnew CecDatapacket;
1437 Empty = true;
1438 }
1439
1440 /// <summary>
1441 /// Pushes a byte of data to this CEC command
1442 /// </summary>
1443 /// <param name="data">The byte to add</param>
1444 void PushBack(uint8_t data)
1445 {
1446 if (Initiator == CecLogicalAddress::Unknown && Destination == CecLogicalAddress::Unknown)
1447 {
1448 Initiator = (CecLogicalAddress) (data >> 4);
1449 Destination = (CecLogicalAddress) (data & 0xF);
1450 }
1451 else if (!OpcodeSet)
1452 {
1453 OpcodeSet = true;
1454 Opcode = (CecOpcode)data;
1455 }
1456 else
1457 {
1458 Parameters->PushBack(data);
1459 }
1460 }
1461
1462 /// <summary>
1463 /// True when this command is empty, false otherwise.
1464 /// </summary>
1465 property bool Empty;
1466 /// <summary>
1467 /// The initiator of the command
1468 /// </summary>
1469 property CecLogicalAddress Initiator;
1470 /// <summary>
1471 /// The destination of the command
1472 /// </summary>
1473 property CecLogicalAddress Destination;
1474 /// <summary>
1475 /// True when the ack bit is set, false otherwise
1476 /// </summary>
1477 property bool Ack;
1478 /// <summary>
1479 /// True when the eom bit is set, false otherwise
1480 /// </summary>
1481 property bool Eom;
1482 /// <summary>
1483 /// The CEC opcode of the command
1484 /// </summary>
1485 property CecOpcode Opcode;
1486 /// <summary>
1487 /// The parameters of this command
1488 /// </summary>
1489 property CecDatapacket ^ Parameters;
1490 /// <summary>
1491 /// True when an opcode is set, false otherwise (poll message)
1492 /// </summary>
1493 property bool OpcodeSet;
1494 /// <summary>
1495 /// The timeout to use when transmitting a command
1496 /// </summary>
1497 property int32_t TransmitTimeout;
1498 };
1499
1500 /// <summary>
1501 /// A key press that was received
1502 /// </summary>
1503 public ref class CecKeypress
1504 {
1505 public:
1506 /// <summary>
1507 /// Create a new key press instance
1508 /// </summary>
1509 /// <param name="keycode">The key code of this key press</param>
1510 /// <param name="duration">The duration of this key press in milliseconds</param>
1511 CecKeypress(CecUserControlCode keycode, unsigned int duration)
1512 {
1513 Keycode = keycode;
1514 Duration = duration;
1515 Empty = false;
1516 }
1517
1518 /// <summary>
1519 /// Create a new empty key press instance
1520 /// </summary>
1521 CecKeypress(void)
1522 {
1523 Keycode = CecUserControlCode::Unknown;
1524 Duration = 0;
1525 Empty = true;
1526 }
1527
1528 /// <summary>
1529 /// True when empty, false otherwise
1530 /// </summary>
1531 property bool Empty;
1532 /// <summary>
1533 /// The key code of this key press
1534 /// </summary>
1535 property CecUserControlCode Keycode;
1536 /// <summary>
1537 /// The duration of this key press in milliseconds
1538 /// </summary>
1539 property unsigned int Duration;
1540 };
1541
1542 /// <summary>
1543 /// A log message that libCEC generated
1544 /// </summary>
1545 public ref class CecLogMessage
1546 {
1547 public:
1548 /// <summary>
1549 /// Create a new log message
1550 /// </summary>
1551 /// <param name="message">The actual message</param>
1552 /// <param name="level">The log level, so the application can choose what type information to display</param>
1553 /// <param name="time">The timestamp of this message, in milliseconds after connecting</param>
1554 CecLogMessage(System::String ^ message, CecLogLevel level, int64_t time)
1555 {
1556 Message = message;
1557 Level = level;
1558 Time = time;
1559 Empty = false;
1560 }
1561
1562 /// <summary>
1563 /// Create a new empty log message
1564 /// </summary>
1565 CecLogMessage(void)
1566 {
1567 Message = "";
1568 Level = CecLogLevel::None;
1569 Time = 0;
1570 Empty = true;
1571 }
1572
1573 /// <summary>
1574 /// True when empty, false otherwise.
1575 /// </summary>
1576 property bool Empty;
1577 /// <summary>
1578 /// The actual message
1579 /// </summary>
1580 property System::String ^Message;
1581 /// <summary>
1582 /// The log level, so the application can choose what type information to display
1583 /// </summary>
1584 property CecLogLevel Level;
1585 /// <summary>
1586 /// The timestamp of this message, in milliseconds after connecting
1587 /// </summary>
1588 property int64_t Time;
1589 };
1590
1591 ref class CecCallbackMethods; //forward declaration
1592
1593 /// <summary>
1594 /// The configuration that libCEC uses.
1595 /// </summary>
1596 public ref class LibCECConfiguration
1597 {
1598 public:
1599 /// <summary>
1600 /// Create a new configuration instance with default settings.
1601 /// </summary>
1602 LibCECConfiguration(void)
1603 {
1604 DeviceName = "";
1605 DeviceTypes = gcnew CecDeviceTypeList();
1606 AutodetectAddress = true;
1607 PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
1608 BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE;
1609 HDMIPort = CEC_DEFAULT_HDMI_PORT;
1610 ClientVersion = CecClientVersion::VersionPre1_5;
1611 ServerVersion = CecServerVersion::VersionPre1_5;
1612 TvVendor = CecVendorId::Unknown;
1613
1614 GetSettingsFromROM = false;
1615 UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1;
1616 ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1;
1617
1618 WakeDevices = gcnew CecLogicalAddresses();
1619 if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1)
1620 WakeDevices->Set(CecLogicalAddress::Tv);
1621
1622 PowerOffDevices = gcnew CecLogicalAddresses();
1623 if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1)
1624 PowerOffDevices->Set(CecLogicalAddress::Broadcast);
1625
1626 PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1;
1627 PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1;
1628
1629 SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1;
1630 LogicalAddresses = gcnew CecLogicalAddresses();
1631 FirmwareVersion = 1;
1632 PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1;
1633 ShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1;
1634 DeviceLanguage = "";
22190f06
LOK
1635 FirmwareBuildDate = gcnew System::DateTime(1970,1,1,0,0,0,0);
1636 CECVersion = (CecVersion)CEC_DEFAULT_SETTING_CEC_VERSION;
1637 AdapterType = CecAdapterType::Unknown;
f9717bcc
LOK
1638 }
1639
1640 /// <summary>
1641 /// Change the callback method pointers in this configuration instance.
1642 /// </summary>
1643 /// <param name="callbacks">The new callbacks</param>
1644 void SetCallbacks(CecCallbackMethods ^callbacks)
1645 {
1646 Callbacks = callbacks;
1647 }
1648
1649 /// <summary>
1650 /// Update this configuration with data received from libCEC
1651 /// </summary>
1652 /// <param name="config">The configuration that was received from libCEC</param>
1653 void Update(const CEC::libcec_configuration &config)
1654 {
1655 DeviceName = gcnew System::String(config.strDeviceName);
1656
1657 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
1658 DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr];
1659
1660 AutodetectAddress = config.bAutodetectAddress == 1;
1661 PhysicalAddress = config.iPhysicalAddress;
1662 BaseDevice = (CecLogicalAddress)config.baseDevice;
1663 HDMIPort = config.iHDMIPort;
1664 ClientVersion = (CecClientVersion)config.clientVersion;
1665 ServerVersion = (CecServerVersion)config.serverVersion;
1666 TvVendor = (CecVendorId)config.tvVendor;
1667
1668 // player specific settings
1669 GetSettingsFromROM = config.bGetSettingsFromROM == 1;
1670 UseTVMenuLanguage = config.bUseTVMenuLanguage == 1;
1671 ActivateSource = config.bActivateSource == 1;
1672
1673 WakeDevices->Clear();
1674 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
1675 if (config.wakeDevices[iPtr])
1676 WakeDevices->Set((CecLogicalAddress)iPtr);
1677
1678 PowerOffDevices->Clear();
1679 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
1680 if (config.powerOffDevices[iPtr])
1681 PowerOffDevices->Set((CecLogicalAddress)iPtr);
1682
1683 PowerOffScreensaver = config.bPowerOffScreensaver == 1;
1684 PowerOffOnStandby = config.bPowerOffOnStandby == 1;
1685
1686 if (ServerVersion >= CecServerVersion::Version1_5_1)
1687 SendInactiveSource = config.bSendInactiveSource == 1;
1688
1689 if (ServerVersion >= CecServerVersion::Version1_5_3)
1690 {
1691 LogicalAddresses->Clear();
1692 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
1693 if (config.logicalAddresses[iPtr])
1694 LogicalAddresses->Set((CecLogicalAddress)iPtr);
1695 }
1696
1697 if (ServerVersion >= CecServerVersion::Version1_6_0)
1698 {
1699 FirmwareVersion = config.iFirmwareVersion;
1700 PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1;
1701 ShutdownOnStandby = config.bShutdownOnStandby == 1;
1702 }
1703
1704 if (ServerVersion >= CecServerVersion::Version1_6_2)
22190f06 1705 {
f9717bcc 1706 DeviceLanguage = gcnew System::String(config.strDeviceLanguage);
22190f06
LOK
1707 FirmwareBuildDate = gcnew System::DateTime(1970,1,1,0,0,0,0);
1708 FirmwareBuildDate = FirmwareBuildDate->AddSeconds(config.iFirmwareBuildDate);
1709 }
f9717bcc
LOK
1710
1711 if (ServerVersion >= CecServerVersion::Version1_6_3)
1712 MonitorOnlyClient = config.bMonitorOnly == 1;
22190f06
LOK
1713
1714 if (ServerVersion >= CecServerVersion::Version1_8_0)
1715 CECVersion = (CecVersion)config.cecVersion;
1716
1717 if (ServerVersion >= CecServerVersion::Version1_8_2)
1718 AdapterType = (CecAdapterType)config.adapterType;
f9717bcc
LOK
1719 }
1720
1721 /// <summary>
1722 /// The device name to use on the CEC bus
1723 /// </summary>
1724 property System::String ^ DeviceName;
1725
1726 /// <summary>
1727 /// The device type(s) to use on the CEC bus for libCEC
1728 /// </summary>
1729 property CecDeviceTypeList ^ DeviceTypes;
1730
1731 /// <summary>
1732 /// True to try to autodetect the physical address, false otherwise
1733 /// </summary>
1734 property bool AutodetectAddress;
1735
1736 /// <summary>
1737 /// The physical address that libCEC uses on the CEC bus
1738 /// </summary>
1739 property uint16_t PhysicalAddress;
1740
1741 /// <summary>
1742 /// The logical address of the device to which the CEC adapter is connected, only used when PhysicalAddress isn't set
1743 /// </summary>
1744 property CecLogicalAddress BaseDevice;
1745
1746 /// <summary>
1747 /// The hdmi port number on the device to which the CEC adapter is connected, only used when PhysicalAddress isn't set
1748 /// </summary>
1749 property uint8_t HDMIPort;
1750
1751 /// <summary>
1752 /// The client API version to use
1753 /// </summary>
1754 property CecClientVersion ClientVersion;
1755
1756 /// <summary>
1757 /// The version of libCEC
1758 /// </summary>
1759 property CecServerVersion ServerVersion;
1760
1761 /// <summary>
1762 /// Override the vendor ID of the TV when set (for quirks mode)
1763 /// </summary>
1764 property CecVendorId TvVendor;
1765
1766 /// <summary>
1767 /// True to read the settings from the EEPROM, which possibly override the settings passed here
1768 /// </summary>
1769 property bool GetSettingsFromROM;
1770
1771 /// <summary>
1772 /// Use the language setting of the TV in the client application. Must be implemented by the client application.
1773 /// </summary>
1774 property bool UseTVMenuLanguage;
1775
1776 /// <summary>
1777 /// Make libCEC the active source when starting the client application
1778 /// </summary>
1779 property bool ActivateSource;
1780
1781 /// <summary>
1782 /// List of devices to send a power on command to when starting the client application
1783 /// </summary>
1784 property CecLogicalAddresses ^WakeDevices;
1785
1786 /// <summary>
1787 /// List of devices to send a standby command to when exiting the client application
1788 /// </summary>
1789 property CecLogicalAddresses ^PowerOffDevices;
1790
1791 /// <summary>
1792 /// Send standby commands when the client application activates the screensaver. Must be implemented by the client application.
1793 /// </summary>
1794 property bool PowerOffScreensaver;
1795
1796 /// <summary>
1797 /// Power off the PC when the TV powers off. Must be implemented by the client application.
1798 /// </summary>
1799 property bool PowerOffOnStandby;
1800
1801 /// <summary>
1802 /// Send an inactive source message when exiting the client application.
1803 /// </summary>
1804 property bool SendInactiveSource;
1805
1806 /// <summary>
1807 /// The list of logical addresses that libCEC is using
1808 /// </summary>
1809 property CecLogicalAddresses ^LogicalAddresses;
1810
1811 /// <summary>
1812 /// The firmware version of the adapter to which libCEC is connected
1813 /// </summary>
1814 property uint16_t FirmwareVersion;
1815
1816 /// <summary>
1817 /// Send standby commands when the client application activates standby mode (S3). Must be implemented by the client application.
1818 /// </summary>
1819 property bool PowerOffDevicesOnStandby;
1820 property bool ShutdownOnStandby;
1821
1822 /// <summary>
1823 /// True to start a monitor-only client, false to start a standard client.
1824 /// </summary>
1825 property bool MonitorOnlyClient;
1826
1827 /// <summary>
1828 /// The language code of the menu language that libCEC reports to other devices.
1829 /// </summary>
1830 property System::String ^ DeviceLanguage;
1831
1832 /// <summary>
1833 /// The callback methods to use.
1834 /// </summary>
1835 property CecCallbackMethods ^ Callbacks;
22190f06
LOK
1836
1837 /// <summary>
1838 /// The build date of the firmware.
1839 /// </summary>
1840 property System::DateTime ^ FirmwareBuildDate;
1841
1842 /// <summary>
1843 /// The CEC version that libCEC uses.
1844 /// </summary>
1845 property CecVersion CECVersion;
1846
1847 /// <summary>
1848 /// The type of adapter that libCEC is connected to.
1849 /// </summary>
1850 property CecAdapterType AdapterType;
f9717bcc
LOK
1851 };
1852
1853 // the callback methods are called by unmanaged code, so we need some delegates for this
1854#pragma unmanaged
1855 // unmanaged callback methods
1856 typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message);
1857 typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key);
1858 typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command);
1859 typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config);
1860 typedef int (__stdcall *ALERTCB) (const CEC::libcec_alert, const CEC::libcec_parameter &data);
1861 typedef int (__stdcall *MENUCB) (const CEC::cec_menu_state newVal);
1862 typedef void (__stdcall *ACTICB) (const CEC::cec_logical_address logicalAddress, const uint8_t bActivated);
1863
8438c41f
LOK
1864 /// <summary>
1865 /// libCEC callback methods. Unmanaged code.
1866 /// </summary>
f9717bcc
LOK
1867 typedef struct
1868 {
8438c41f
LOK
1869 /// <summary>
1870 /// Log message callback
1871 /// </summary>
f9717bcc 1872 LOGCB logCB;
8438c41f
LOK
1873 /// <summary>
1874 /// Key press/release callback
1875 /// </summary>
f9717bcc 1876 KEYCB keyCB;
8438c41f
LOK
1877 /// <summary>
1878 /// Raw CEC data callback
1879 /// </summary>
f9717bcc 1880 COMMANDCB commandCB;
8438c41f
LOK
1881 /// <summary>
1882 /// Updated configuration callback
1883 /// </summary>
f9717bcc 1884 CONFIGCB configCB;
8438c41f
LOK
1885 /// <summary>
1886 /// Alert message callback
1887 /// </summary>
f9717bcc 1888 ALERTCB alertCB;
8438c41f
LOK
1889 /// <summary>
1890 /// Menu status change callback
1891 /// </summary>
f9717bcc 1892 MENUCB menuCB;
8438c41f
LOK
1893 /// <summary>
1894 /// Source (de)activated callback
1895 /// </summary>
f9717bcc
LOK
1896 ACTICB sourceActivatedCB;
1897 } UnmanagedCecCallbacks;
1898
1899 static PLATFORM::CMutex g_callbackMutex;
1900 static std::vector<UnmanagedCecCallbacks> g_unmanagedCallbacks;
dc6366e8 1901 static CEC::ICECCallbacks g_cecCallbacks;
4ef3b314 1902
8438c41f
LOK
1903 /// <summary>
1904 /// Called by libCEC to send back a log message to the application
1905 /// </summary>
1906 /// <param name="cbParam">Pointer to the callback struct</param>
1907 /// <param name="message">The log message</param>
1908 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
1909 int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message)
1910 {
1911 if (cbParam)
1912 {
1913 size_t iPtr = (size_t)cbParam;
1914 PLATFORM::CLockObject lock(g_callbackMutex);
1915 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
1916 return g_unmanagedCallbacks[iPtr].logCB(message);
1917 }
1918 return 0;
1919 }
1920
8438c41f
LOK
1921 /// <summary>
1922 /// Called by libCEC to send back a key press or release to the application
1923 /// </summary>
1924 /// <param name="cbParam">Pointer to the callback struct</param>
1925 /// <param name="key">The key press command that libCEC received</param>
1926 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
1927 int CecKeyPressCB(void *cbParam, const CEC::cec_keypress &key)
1928 {
1929 if (cbParam)
1930 {
1931 size_t iPtr = (size_t)cbParam;
1932 PLATFORM::CLockObject lock(g_callbackMutex);
1933 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
1934 return g_unmanagedCallbacks[iPtr].keyCB(key);
1935 }
1936 return 0;
1937 }
1938
8438c41f
LOK
1939 /// <summary>
1940 /// Called by libCEC to send back raw CEC data to the application
1941 /// </summary>
1942 /// <param name="cbParam">Pointer to the callback struct</param>
1943 /// <param name="command">The raw CEC data</param>
1944 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
1945 int CecCommandCB(void *cbParam, const CEC::cec_command &command)
1946 {
1947 if (cbParam)
1948 {
1949 size_t iPtr = (size_t)cbParam;
1950 PLATFORM::CLockObject lock(g_callbackMutex);
1951 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
1952 return g_unmanagedCallbacks[iPtr].commandCB(command);
1953 }
1954 return 0;
1955 }
4ef3b314 1956
8438c41f
LOK
1957 /// <summary>
1958 /// Called by libCEC to send back an updated configuration to the application
1959 /// </summary>
1960 /// <param name="cbParam">Pointer to the callback struct</param>
1961 /// <param name="config">The new configuration</param>
1962 /// <return>1 when handled, 0 otherwise</return>
32403cc3 1963 int CecConfigCB(void *cbParam, const CEC::libcec_configuration &config)
f9717bcc
LOK
1964 {
1965 if (cbParam)
1966 {
1967 size_t iPtr = (size_t)cbParam;
1968 PLATFORM::CLockObject lock(g_callbackMutex);
1969 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
1970 return g_unmanagedCallbacks[iPtr].configCB(config);
1971 }
1972 return 0;
1973 }
1974
8438c41f
LOK
1975 /// <summary>
1976 /// Called by libCEC to send back an alert message to the application
1977 /// </summary>
1978 /// <param name="cbParam">Pointer to the callback struct</param>
1979 /// <param name="data">The alert message</param>
1980 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
1981 int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter &data)
1982 {
1983 if (cbParam)
1984 {
1985 size_t iPtr = (size_t)cbParam;
1986 PLATFORM::CLockObject lock(g_callbackMutex);
1987 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
1988 return g_unmanagedCallbacks[iPtr].alertCB(alert, data);
1989 }
1990 return 0;
1991 }
1992
8438c41f
LOK
1993 /// <summary>
1994 /// Called by libCEC to send back a menu state change to the application
1995 /// </summary>
1996 /// <param name="cbParam">Pointer to the callback struct</param>
1997 /// <param name="newVal">The new menu state</param>
1998 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
1999 int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal)
2000 {
2001 if (cbParam)
2002 {
2003 size_t iPtr = (size_t)cbParam;
2004 PLATFORM::CLockObject lock(g_callbackMutex);
2005 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
2006 return g_unmanagedCallbacks[iPtr].menuCB(newVal);
2007 }
2008 return 0;
2009 }
dc6366e8 2010
8438c41f
LOK
2011 /// <summary>
2012 /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated
2013 /// </summary>
2014 /// <param name="cbParam">Pointer to the callback struct</param>
2015 /// <param name="logicalAddress">The logical address that was (de)activated</param>
2016 /// <param name="activated">True when activated, false when deactivated</param>
2017 void CecSourceActivatedCB(void *cbParam, const CEC::cec_logical_address logicalAddress, const uint8_t activated)
f9717bcc
LOK
2018 {
2019 if (cbParam)
2020 {
2021 size_t iPtr = (size_t)cbParam;
2022 PLATFORM::CLockObject lock(g_callbackMutex);
2023 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
8438c41f 2024 g_unmanagedCallbacks[iPtr].sourceActivatedCB(logicalAddress, activated);
f9717bcc
LOK
2025 }
2026 }
2027
2028#pragma managed
2029 // delegates for the unmanaged callback methods
2030 public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &);
2031 public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &);
2032 public delegate int CecCommandManagedDelegate(const CEC::cec_command &);
2033 public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &);
2034 public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &);
2035 public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state newVal);
2036 public delegate void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated);
2037
8438c41f
LOK
2038 /// <summary>
2039 /// Assign the callback methods in the g_cecCallbacks struct
2040 /// </summary>
f9717bcc
LOK
2041 void AssignCallbacks()
2042 {
2043 g_cecCallbacks.CBCecLogMessage = CecLogMessageCB;
2044 g_cecCallbacks.CBCecKeyPress = CecKeyPressCB;
2045 g_cecCallbacks.CBCecCommand = CecCommandCB;
2046 g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB;
2047 g_cecCallbacks.CBCecAlert = CecAlertCB;
2048 g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB;
2049 g_cecCallbacks.CBCecSourceActivated = CecSourceActivatedCB;
2050 }
2051
2052 /// <summary>
2053 /// The callback methods that libCEC uses
2054 /// </summary>
2055 public ref class CecCallbackMethods
2056 {
2057 public:
11fea069
LOK
2058 CecCallbackMethods(void)
2059 {
f9717bcc
LOK
2060 m_iCallbackPtr = -1;
2061 AssignCallbacks();
11fea069
LOK
2062 m_bHasCallbacks = false;
2063 m_bDelegatesCreated = false;
2064 }
4ef3b314 2065
f9717bcc 2066 ~CecCallbackMethods(void)
dc6366e8
LOK
2067 {
2068 DestroyDelegates();
2069 }
2070
8438c41f
LOK
2071 /// <summary>
2072 /// Pointer to the callbacks struct entry
2073 /// </summary>
f9717bcc
LOK
2074 size_t GetCallbackPtr(void)
2075 {
2076 PLATFORM::CLockObject lock(g_callbackMutex);
2077 return m_iCallbackPtr;
2078 }
2079
2080 protected:
2081 !CecCallbackMethods(void)
2082 {
2083 DestroyDelegates();
2084 }
2085
2086 public:
8438c41f
LOK
2087 /// <summary>
2088 /// Disable callback methods
2089 /// </summary>
f9717bcc
LOK
2090 virtual void DisableCallbacks(void)
2091 {
2092 DestroyDelegates();
2093 }
2094
8438c41f
LOK
2095 /// <summary>
2096 /// Enable callback methods
2097 /// </summary>
2098 /// <param name="callbacks">Callback methods to activate</param>
2099 /// <return>true when handled, false otherwise</return>
f9717bcc
LOK
2100 virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks)
2101 {
11fea069 2102 CreateDelegates();
f9717bcc
LOK
2103 if (!m_bHasCallbacks)
2104 {
2105 m_bHasCallbacks = true;
2106 m_callbacks = callbacks;
2107 return true;
2108 }
2109
2110 return false;
2111 }
2112
2113 /// <summary>
8438c41f
LOK
2114 /// Called by libCEC to send back a log message to the application.
2115 /// Override in the application to handle this callback.
f9717bcc
LOK
2116 /// </summary>
2117 /// <param name="message">The log message</param>
8438c41f 2118 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
2119 virtual int ReceiveLogMessage(CecLogMessage ^ message)
2120 {
2121 return 0;
2122 }
2123
2124 /// <summary>
8438c41f
LOK
2125 /// Called by libCEC to send back a key press or release to the application.
2126 /// Override in the application to handle this callback.
f9717bcc
LOK
2127 /// </summary>
2128 /// <param name="key">The key press command that libCEC received</param>
8438c41f 2129 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
2130 virtual int ReceiveKeypress(CecKeypress ^ key)
2131 {
2132 return 0;
2133 }
2134
2135 /// <summary>
8438c41f
LOK
2136 /// Called by libCEC to send back raw CEC data to the application.
2137 /// Override in the application to handle this callback.
f9717bcc
LOK
2138 /// </summary>
2139 /// <param name="command">The raw CEC data</param>
8438c41f 2140 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
2141 virtual int ReceiveCommand(CecCommand ^ command)
2142 {
2143 return 0;
2144 }
2145
2146 /// <summary>
8438c41f
LOK
2147 /// Called by libCEC to send back an updated configuration to the application.
2148 /// Override in the application to handle this callback.
f9717bcc
LOK
2149 /// </summary>
2150 /// <param name="config">The new configuration</param>
8438c41f 2151 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
2152 virtual int ConfigurationChanged(LibCECConfiguration ^ config)
2153 {
2154 return 0;
2155 }
2156
2157 /// <summary>
8438c41f
LOK
2158 /// Called by libCEC to send back an alert message to the application.
2159 /// Override in the application to handle this callback.
f9717bcc
LOK
2160 /// </summary>
2161 /// <param name="data">The alert message</param>
8438c41f 2162 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
2163 virtual int ReceiveAlert(CecAlert alert, CecParameter ^ data)
2164 {
2165 return 0;
2166 }
2167
2168 /// <summary>
8438c41f
LOK
2169 /// Called by libCEC to send back a menu state change to the application.
2170 /// Override in the application to handle this callback.
f9717bcc
LOK
2171 /// </summary>
2172 /// <param name="newVal">The new menu state</param>
8438c41f 2173 /// <return>1 when handled, 0 otherwise</return>
f9717bcc
LOK
2174 virtual int ReceiveMenuStateChange(CecMenuState newVal)
2175 {
2176 return 0;
2177 }
2178
2179 /// <summary>
8438c41f
LOK
2180 /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated.
2181 /// Override in the application to handle this callback.
f9717bcc
LOK
2182 /// </summary>
2183 /// <param name="logicalAddress">The logical address that was (de)activated</param>
2184 /// <param name="activated">True when activated, false when deactivated</param>
2185 virtual void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
2186 {
2187 }
2188
2189 protected:
2190 // managed callback methods
2191 int CecLogMessageManaged(const CEC::cec_log_message &message)
2192 {
2193 int iReturn(0);
2194 if (m_bHasCallbacks)
2195 iReturn = m_callbacks->ReceiveLogMessage(gcnew CecLogMessage(gcnew System::String(message.message), (CecLogLevel)message.level, message.time));
2196 return iReturn;
2197 }
2198
2199 int CecKeyPressManaged(const CEC::cec_keypress &key)
2200 {
2201 int iReturn(0);
2202 if (m_bHasCallbacks)
2203 iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration));
2204 return iReturn;
2205 }
2206
2207 int CecCommandManaged(const CEC::cec_command &command)
2208 {
2209 int iReturn(0);
2210 if (m_bHasCallbacks)
2211 {
2212 CecCommand ^ newCommand = gcnew CecCommand((CecLogicalAddress)command.initiator, (CecLogicalAddress)command.destination, command.ack == 1 ? true : false, command.eom == 1 ? true : false, (CecOpcode)command.opcode, command.transmit_timeout);
2213 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
2214 newCommand->Parameters->PushBack(command.parameters[iPtr]);
2215 iReturn = m_callbacks->ReceiveCommand(newCommand);
2216 }
2217 return iReturn;
2218 }
2219
2220 int CecConfigManaged(const CEC::libcec_configuration &config)
2221 {
2222 int iReturn(0);
2223 if (m_bHasCallbacks)
2224 {
2225 LibCECConfiguration ^netConfig = gcnew LibCECConfiguration();
2226 netConfig->Update(config);
2227 iReturn = m_callbacks->ConfigurationChanged(netConfig);
2228 }
2229 return iReturn;
2230 }
2231
2232 int CecAlertManaged(const CEC::libcec_alert alert, const CEC::libcec_parameter &data)
2233 {
2234 int iReturn(0);
2235 if (m_bHasCallbacks)
2236 {
2237 CecParameterType newType = (CecParameterType)data.paramType;
2238 if (newType == CecParameterType::ParameterTypeString)
2239 {
2240 System::String ^ newData = gcnew System::String((const char *)data.paramData, 0, 128);
2241 CecParameter ^ newParam = gcnew CecParameter(newType, newData);
2242 iReturn = m_callbacks->ReceiveAlert((CecAlert)alert, newParam);
2243 }
2244 }
2245 return iReturn;
2246 }
2247
2248 int CecMenuManaged(const CEC::cec_menu_state newVal)
2249 {
2250 int iReturn(0);
2251 if (m_bHasCallbacks)
2252 {
2253 iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal);
2254 }
2255 return iReturn;
2256 }
2257
2258 void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated)
2259 {
2260 if (m_bHasCallbacks)
2261 m_callbacks->SourceActivated((CecLogicalAddress)logicalAddress, bActivated == 1);
2262 }
2263
2264 void DestroyDelegates()
2265 {
11fea069 2266 m_bHasCallbacks = false;
f9717bcc
LOK
2267 if (m_bDelegatesCreated)
2268 {
11fea069 2269 m_bDelegatesCreated = false;
f9717bcc
LOK
2270 m_logMessageGCHandle.Free();
2271 m_keypressGCHandle.Free();
2272 m_commandGCHandle.Free();
2273 m_alertGCHandle.Free();
2274 m_menuGCHandle.Free();
2275 m_sourceActivatedGCHandle.Free();
2276 }
2277 }
4ef3b314 2278
11fea069
LOK
2279 void CreateDelegates()
2280 {
2281 DestroyDelegates();
2282
2283 if (!m_bDelegatesCreated)
2284 {
2285 msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context();
2286
2287 // create the delegate method for the log message callback
dc6366e8
LOK
2288 m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged);
2289 m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate);
f9717bcc 2290 m_logMessageCallback = static_cast<LOGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer());
11fea069
LOK
2291
2292 // create the delegate method for the keypress callback
dc6366e8
LOK
2293 m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged);
2294 m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate);
f9717bcc 2295 m_keypressCallback = static_cast<KEYCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer());
11fea069
LOK
2296
2297 // create the delegate method for the command callback
dc6366e8
LOK
2298 m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged);
2299 m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate);
f9717bcc 2300 m_commandCallback = static_cast<COMMANDCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer());
11fea069
LOK
2301
2302 // create the delegate method for the configuration change callback
dc6366e8
LOK
2303 m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged);
2304 m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate);
f9717bcc 2305 m_configCallback = static_cast<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer());
11fea069 2306
5ee37222 2307 // create the delegate method for the alert callback
dc6366e8
LOK
2308 m_alertDelegate = gcnew CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged);
2309 m_alertGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate);
f9717bcc 2310 m_alertCallback = static_cast<ALERTCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer());
5ee37222 2311
c3a20edb 2312 // create the delegate method for the menu callback
dc6366e8
LOK
2313 m_menuDelegate = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged);
2314 m_menuGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate);
f9717bcc 2315 m_menuCallback = static_cast<MENUCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer());
c3a20edb 2316
f9717bcc 2317 // create the delegate method for the source activated callback
dc6366e8
LOK
2318 m_sourceActivatedDelegate = gcnew CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged);
2319 m_sourceActivatedGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate);
f9717bcc 2320 m_sourceActivatedCallback = static_cast<ACTICB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate).ToPointer());
29d5198c 2321
11fea069 2322 delete context;
dc6366e8 2323
f9717bcc
LOK
2324 UnmanagedCecCallbacks unmanagedCallbacks;
2325 unmanagedCallbacks.logCB = m_logMessageCallback;
2326 unmanagedCallbacks.keyCB = m_keypressCallback;
2327 unmanagedCallbacks.commandCB = m_commandCallback;
2328 unmanagedCallbacks.configCB = m_configCallback;
2329 unmanagedCallbacks.alertCB = m_alertCallback;
2330 unmanagedCallbacks.menuCB = m_menuCallback;
2331 unmanagedCallbacks.sourceActivatedCB = m_sourceActivatedCallback;
2332
2333 PLATFORM::CLockObject lock(g_callbackMutex);
2334 g_unmanagedCallbacks.push_back(unmanagedCallbacks);
2335 m_iCallbackPtr = g_unmanagedCallbacks.size() - 1;
2336 m_bDelegatesCreated = true;
11fea069
LOK
2337 }
2338 }
2339
f9717bcc
LOK
2340 CecLogMessageManagedDelegate ^ m_logMessageDelegate;
2341 static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle;
2342 LOGCB m_logMessageCallback;
4ef3b314 2343
f9717bcc
LOK
2344 CecKeyPressManagedDelegate ^ m_keypressDelegate;
2345 static System::Runtime::InteropServices::GCHandle m_keypressGCHandle;
2346 KEYCB m_keypressCallback;
4ef3b314 2347
f9717bcc
LOK
2348 CecCommandManagedDelegate ^ m_commandDelegate;
2349 static System::Runtime::InteropServices::GCHandle m_commandGCHandle;
2350 COMMANDCB m_commandCallback;
4ef3b314 2351
f9717bcc
LOK
2352 CecConfigManagedDelegate ^ m_configDelegate;
2353 static System::Runtime::InteropServices::GCHandle m_configGCHandle;
2354 CONFIGCB m_configCallback;
32403cc3 2355
f9717bcc
LOK
2356 CecAlertManagedDelegate ^ m_alertDelegate;
2357 static System::Runtime::InteropServices::GCHandle m_alertGCHandle;
2358 ALERTCB m_alertCallback;
5ee37222 2359
f9717bcc
LOK
2360 CecMenuManagedDelegate ^ m_menuDelegate;
2361 static System::Runtime::InteropServices::GCHandle m_menuGCHandle;
2362 MENUCB m_menuCallback;
c3a20edb 2363
f9717bcc
LOK
2364 CecSourceActivatedManagedDelegate ^ m_sourceActivatedDelegate;
2365 static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle;
2366 ACTICB m_sourceActivatedCallback;
29d5198c 2367
f9717bcc
LOK
2368 CecCallbackMethods ^ m_callbacks;
2369 bool m_bHasCallbacks;
11fea069 2370 bool m_bDelegatesCreated;
f9717bcc
LOK
2371 size_t m_iCallbackPtr;
2372 };
4ef3b314 2373}