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