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