10a0fa946914c1b1cf22bf8d8c62f9bc8dd3056f
[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 = 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 Toshiba = 0x000039,
768 Samsung = 0x0000F0,
769 Denon = 0x0005CD,
770 Loewe = 0x000982,
771 Onkyo = 0x0009B0,
772 Medion = 0x000CB8,
773 Akai = 0x0020C7,
774 AOC = 0x002467,
775 Panasonic = 0x008045,
776 Philips = 0x00903E,
777 Daewoo = 0x009053,
778 Yamaha = 0x00A0DE,
779 Grundig = 0x00D0D5,
780 Pioneer = 0x00E036,
781 LG = 0x00E091,
782 Sharp = 0x08001F,
783 Sony = 0x080046,
784 Broadcom = 0x18C086,
785 Vizio = 0x6B746D,
786 Benq = 0x8065E9,
787 Unknown = 0
788 };
789
790 /// <summary>
791 /// Audio status of audio system / AVR devices
792 /// </summary>
793 public enum class CecAudioStatus
794 {
795 /// <summary>
796 /// Muted
797 /// </summary>
798 MuteStatusMask = 0x80,
799 /// <summary>
800 /// Not muted, volume status mask
801 /// </summary>
802 VolumeStatusMask = 0x7F,
803 /// <summary>
804 /// Minumum volume
805 /// </summary>
806 VolumeMin = 0x00,
807 /// <summary>
808 /// Maximum volume
809 /// </summary>
810 VolumeMax = 0x64,
811 /// <summary>
812 /// Unknown status
813 /// </summary>
814 VolumeStatusUnknown = 0x7F
815 };
816
817 /// <summary>
818 /// CEC opcodes, as described in the HDMI CEC specification
819 /// </summary>
820 public enum class CecOpcode
821 {
822 /// <summary>
823 /// Active source
824 /// </summary>
825 ActiveSource = 0x82,
826 /// <summary>
827 /// Image view on: power on display for image display
828 /// </summary>
829 ImageViewOn = 0x04,
830 /// <summary>
831 /// Text view on: power on display for text display
832 /// </summary>
833 TextViewOn = 0x0D,
834 /// <summary>
835 /// Device no longer is the active source
836 /// </summary>
837 InactiveSource = 0x9D,
838 /// <summary>
839 /// Request which device has the active source status
840 /// </summary>
841 RequestActiveSource = 0x85,
842 /// <summary>
843 /// Routing change for HDMI switches
844 /// </summary>
845 RoutingChange = 0x80,
846 /// <summary>
847 /// Routing information for HDMI switches
848 /// </summary>
849 RoutingInformation = 0x81,
850 /// <summary>
851 /// Change the stream path to the given physical address
852 /// </summary>
853 SetStreamPath = 0x86,
854 /// <summary>
855 /// Inform that a device went into standby mode
856 /// </summary>
857 Standby = 0x36,
858 /// <summary>
859 /// Stop recording
860 /// </summary>
861 RecordOff = 0x0B,
862 /// <summary>
863 /// Start recording
864 /// </summary>
865 RecordOn = 0x09,
866 /// <summary>
867 /// Recording status information
868 /// </summary>
869 RecordStatus = 0x0A,
870 /// <summary>
871 /// Record current display
872 /// </summary>
873 RecordTvScreen = 0x0F,
874 /// <summary>
875 /// Clear analogue timer
876 /// </summary>
877 ClearAnalogueTimer = 0x33,
878 /// <summary>
879 /// Clear digital timer
880 /// </summary>
881 ClearDigitalTimer = 0x99,
882 /// <summary>
883 /// Clear external timer
884 /// </summary>
885 ClearExternalTimer = 0xA1,
886 /// <summary>
887 /// Set analogue timer
888 /// </summary>
889 SetAnalogueTimer = 0x34,
890 /// <summary>
891 /// Set digital timer
892 /// </summary>
893 SetDigitalTimer = 0x97,
894 /// <summary>
895 /// Set external timer
896 /// </summary>
897 SetExternalTimer = 0xA2,
898 /// <summary>
899 /// Set program title of a timer
900 /// </summary>
901 SetTimerProgramTitle = 0x67,
902 /// <summary>
903 /// Timer status cleared
904 /// </summary>
905 TimerClearedStatus = 0x43,
906 /// <summary>
907 /// Timer status information
908 /// </summary>
909 TimerStatus = 0x35,
910 /// <summary>
911 /// CEC version used by a device
912 /// </summary>
913 CecVersion = 0x9E,
914 /// <summary>
915 /// Request CEC version of a device
916 /// </summary>
917 GetCecVersion = 0x9F,
918 /// <summary>
919 /// Request physical address of a device
920 /// </summary>
921 GivePhysicalAddress = 0x83,
922 /// <summary>
923 /// Request language code of the menu language of a device
924 /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/
925 /// </summary>
926 GetMenuLanguage = 0x91,
927 /// <summary>
928 /// Report the physical address
929 /// </summary>
930 ReportPhysicalAddress = 0x84,
931 /// <summary>
932 /// Report the language code of the menu language
933 /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/
934 /// </summary>
935 SetMenuLanguage = 0x32,
936 /// <summary>
937 /// Deck control for playback and recording devices
938 /// </summary>
939 DeckControl = 0x42,
940 /// <summary>
941 /// Deck status for playback and recording devices
942 /// </summary>
943 DeckStatus = 0x1B,
944 /// <summary>
945 /// Request deck status from playback and recording devices
946 /// </summary>
947 GiveDeckStatus = 0x1A,
948 /// <summary>
949 /// Start playback on playback and recording devices
950 /// </summary>
951 Play = 0x41,
952 /// <summary>
953 /// Request tuner status
954 /// </summary>
955 GiveTunerDeviceStatus = 0x08,
956 /// <summary>
957 /// Select analogue service on a tuner
958 /// </summary>
959 SelectAnalogueService = 0x92,
960 /// <summary>
961 /// Select digital service on a tuner
962 /// </summary>
963 SelectDigtalService = 0x93,
964 /// <summary>
965 /// Report tuner device status
966 /// </summary>
967 TunerDeviceStatus = 0x07,
968 /// <summary>
969 /// Tuner step decrement
970 /// </summary>
971 TunerStepDecrement = 0x06,
972 /// <summary>
973 /// Tuner step increment
974 /// </summary>
975 TunerStepIncrement = 0x05,
976 /// <summary>
977 /// Report device vendor ID
978 /// </summary>
979 DeviceVendorId = 0x87,
980 /// <summary>
981 /// Request device vendor ID
982 /// </summary>
983 GiveDeviceVendorId = 0x8C,
984 /// <summary>
985 /// Vendor specific command
986 /// </summary>
987 VendorCommand = 0x89,
988 /// <summary>
989 /// Vendor specific command with vendor ID
990 /// </summary>
991 VendorCommandWithId = 0xA0,
992 /// <summary>
993 /// Vendor specific remote button pressed
994 /// </summary>
995 VendorRemoteButtonDown = 0x8A,
996 /// <summary>
997 /// Vendor specific remote button released
998 /// </summary>
999 VendorRemoteButtonUp = 0x8B,
1000 /// <summary>
1001 /// Display / clear OSD string
1002 /// </summary>
1003 SetOsdString = 0x64,
1004 /// <summary>
1005 /// Request device OSD name
1006 /// </summary>
1007 GiveOsdName = 0x46,
1008 /// <summary>
1009 /// Report device OSD name
1010 /// </summary>
1011 SetOsdName = 0x47,
1012 /// <summary>
1013 /// Request device menu status
1014 /// </summary>
1015 MenuRequest = 0x8D,
1016 /// <summary>
1017 /// Report device menu status
1018 /// </summary>
1019 MenuStatus = 0x8E,
1020 /// <summary>
1021 /// Remote button pressed
1022 /// </summary>
1023 UserControlPressed = 0x44,
1024 /// <summary>
1025 /// Remote button released
1026 /// </summary>
1027 UserControlRelease = 0x45,
1028 /// <summary>
1029 /// Request device power status
1030 /// </summary>
1031 GiveDevicePowerStatus = 0x8F,
1032 /// <summary>
1033 /// Report device power status
1034 /// </summary>
1035 ReportPowerStatus = 0x90,
1036 /// <summary>
1037 /// Feature abort / unsupported command
1038 /// </summary>
1039 FeatureAbort = 0x00,
1040 /// <summary>
1041 /// Abort command
1042 /// </summary>
1043 Abort = 0xFF,
1044 /// <summary>
1045 /// Give audio status
1046 /// </summary>
1047 GiveAudioStatus = 0x71,
1048 /// <summary>
1049 /// Give audiosystem mode
1050 /// </summary>
1051 GiveSystemAudioMode = 0x7D,
1052 /// <summary>
1053 /// Report device audio status
1054 /// </summary>
1055 ReportAudioStatus = 0x7A,
1056 /// <summary>
1057 /// Set audiosystem mode
1058 /// </summary>
1059 SetSystemAudioMode = 0x72,
1060 /// <summary>
1061 /// Request audiosystem mode
1062 /// </summary>
1063 SystemAudioModeRequest = 0x70,
1064 /// <summary>
1065 /// Report audiosystem mode
1066 /// </summary>
1067 SystemAudioModeStatus = 0x7E,
1068 /// <summary>
1069 /// Set audio bitrate
1070 /// </summary>
1071 SetAudioRate = 0x9A,
1072 /// <summary>
1073 /// When this opcode is set, no opcode will be sent to the device / poll message
1074 /// This is one of the reserved numbers
1075 /// </summary>
1076 None = 0xFD
1077 };
1078
1079 /// <summary>
1080 /// Audiosystem status
1081 /// </summary>
1082 public enum class CecSystemAudioStatus
1083 {
1084 /// <summary>
1085 /// Turned off
1086 /// </summary>
1087 Off = 0,
1088 /// <summary>
1089 /// Turned on
1090 /// </summary>
1091 On = 1
1092 };
1093
1094 /// <summary>
1095 /// libCEC client application version
1096 /// </summary>
1097 public enum class CecClientVersion
1098 {
1099 /// <summary>
1100 /// before v1.5.0
1101 /// </summary>
1102 VersionPre1_5 = 0,
1103 /// <summary>
1104 /// v1.5.0
1105 /// </summary>
1106 Version1_5_0 = 0x1500,
1107 /// <summary>
1108 /// v1.5.1
1109 /// </summary>
1110 Version1_5_1 = 0x1501,
1111 /// <summary>
1112 /// v1.5.2
1113 /// </summary>
1114 Version1_5_2 = 0x1502,
1115 /// <summary>
1116 /// v1.5.3
1117 /// </summary>
1118 Version1_5_3 = 0x1503,
1119 /// <summary>
1120 /// v1.6.0
1121 /// </summary>
1122 Version1_6_0 = 0x1600,
1123 /// <summary>
1124 /// v1.6.1
1125 /// </summary>
1126 Version1_6_1 = 0x1601,
1127 /// <summary>
1128 /// v1.6.2
1129 /// </summary>
1130 Version1_6_2 = 0x1602,
1131 /// <summary>
1132 /// v1.6.3
1133 /// </summary>
1134 Version1_6_3 = 0x1603,
1135 /// <summary>
1136 /// v1.7.0
1137 /// </summary>
1138 Version1_7_0 = 0x1700,
1139 /// <summary>
1140 /// v1.7.1
1141 /// </summary>
1142 Version1_7_1 = 0x1701,
1143 /// <summary>
1144 /// v1.7.2
1145 /// </summary>
1146 Version1_7_2 = 0x1702,
1147 /// <summary>
1148 /// v1.8.0
1149 /// </summary>
1150 Version1_8_0 = 0x1800,
1151 /// <summary>
1152 /// v1.8.1
1153 /// </summary>
1154 Version1_8_1 = 0x1801,
1155 /// <summary>
1156 /// v1.8.2
1157 /// </summary>
1158 Version1_8_2 = 0x1802,
1159 /// <summary>
1160 /// v1.9.0
1161 /// </summary>
1162 Version1_9_0 = 0x1900,
1163 /// <summary>
1164 /// v2.0.0-pre
1165 /// </summary>
1166 Version1_99_0 = 0x1990,
1167 /// <summary>
1168 /// v2.0.0
1169 /// </summary>
1170 Version2_0_0 = 0x2000,
1171 /// <summary>
1172 /// v2.0.1
1173 /// </summary>
1174 Version2_0_1 = 0x2001,
1175 /// <summary>
1176 /// v2.0.2
1177 /// </summary>
1178 Version2_0_2 = 0x2002,
1179 /// <summary>
1180 /// v2.0.3
1181 /// </summary>
1182 Version2_0_3 = 0x2003,
1183 /// <summary>
1184 /// v2.0.4
1185 /// </summary>
1186 Version2_0_4 = 0x2004,
1187 /// <summary>
1188 /// v2.0.5
1189 /// </summary>
1190 Version2_0_5 = 0x2005,
1191 /// <summary>
1192 /// v2.1.0
1193 /// </summary>
1194 Version2_1_0 = 0x2100
1195 };
1196
1197 /// <summary>
1198 /// libCEC version
1199 /// </summary>
1200 public enum class CecServerVersion
1201 {
1202 /// <summary>
1203 /// before v1.5.0
1204 /// </summary>
1205 VersionPre1_5 = 0,
1206 /// <summary>
1207 /// v1.5.0
1208 /// </summary>
1209 Version1_5_0 = 0x1500,
1210 /// <summary>
1211 /// v1.5.1
1212 /// </summary>
1213 Version1_5_1 = 0x1501,
1214 /// <summary>
1215 /// v1.5.2
1216 /// </summary>
1217 Version1_5_2 = 0x1502,
1218 /// <summary>
1219 /// v1.5.3
1220 /// </summary>
1221 Version1_5_3 = 0x1503,
1222 /// <summary>
1223 /// v1.6.0
1224 /// </summary>
1225 Version1_6_0 = 0x1600,
1226 /// <summary>
1227 /// v1.6.1
1228 /// </summary>
1229 Version1_6_1 = 0x1601,
1230 /// <summary>
1231 /// v1.6.2
1232 /// </summary>
1233 Version1_6_2 = 0x1602,
1234 /// <summary>
1235 /// v1.6.3
1236 /// </summary>
1237 Version1_6_3 = 0x1603,
1238 /// <summary>
1239 /// v1.7.0
1240 /// </summary>
1241 Version1_7_0 = 0x1700,
1242 /// <summary>
1243 /// v1.7.1
1244 /// </summary>
1245 Version1_7_1 = 0x1701,
1246 /// <summary>
1247 /// v1.7.2
1248 /// </summary>
1249 Version1_7_2 = 0x1702,
1250 /// <summary>
1251 /// v1.8.0
1252 /// </summary>
1253 Version1_8_0 = 0x1800,
1254 /// <summary>
1255 /// v1.8.1
1256 /// </summary>
1257 Version1_8_1 = 0x1801,
1258 /// <summary>
1259 /// v1.8.2
1260 /// </summary>
1261 Version1_8_2 = 0x1802,
1262 /// <summary>
1263 /// v1.9.0
1264 /// </summary>
1265 Version1_9_0 = 0x1900,
1266 /// <summary>
1267 /// v2.0.0-pre
1268 /// </summary>
1269 Version1_99_0 = 0x1990,
1270 /// <summary>
1271 /// v2.0.0
1272 /// </summary>
1273 Version2_0_0 = 0x2000,
1274 /// <summary>
1275 /// v2.0.1
1276 /// </summary>
1277 Version2_0_1 = 0x2001,
1278 /// <summary>
1279 /// v2.0.2
1280 /// </summary>
1281 Version2_0_2 = 0x2002,
1282 /// <summary>
1283 /// v2.0.3
1284 /// </summary>
1285 Version2_0_3 = 0x2003,
1286 /// <summary>
1287 /// v2.0.4
1288 /// </summary>
1289 Version2_0_4 = 0x2004,
1290 /// <summary>
1291 /// v2.0.5
1292 /// </summary>
1293 Version2_0_5 = 0x2005,
1294 /// <summary>
1295 /// v2.1.0
1296 /// </summary>
1297 Version2_1_0 = 0x2100
1298 };
1299
1300 /// <summary>
1301 /// Type of adapter to which libCEC is connected
1302 /// </summary>
1303 public enum class CecAdapterType
1304 {
1305 /// <summary>
1306 /// Unknown adapter type
1307 /// </summary>
1308 Unknown = 0,
1309 /// <summary>
1310 /// Pulse-Eight USB-CEC adapter
1311 /// </summary>
1312 PulseEightExternal = 0x1,
1313 /// <summary>
1314 /// Pulse-Eight CEC daughterboard
1315 /// </summary>
1316 PulseEightDaughterboard = 0x2,
1317 /// <summary>
1318 /// Raspberry Pi
1319 /// </summary>
1320 RaspberryPi = 0x100,
1321 /// <summary>
1322 /// TDA995x
1323 /// </summary>
1324 TDA995x = 0x200
1325 };
1326
1327 /// <summary>
1328 /// Descriptor of a CEC adapter, returned when scanning for adapters that are connected to the system
1329 /// </summary>
1330 public ref class CecAdapter
1331 {
1332 public:
1333 /// <summary>
1334 /// Create a new CEC adapter descriptor
1335 /// </summary>
1336 /// <param name="path"> The path descriptor for this CEC adapter</param>
1337 /// <param name="comPort">The COM port of this CEC adapter</param>
1338 CecAdapter(System::String ^ path, System::String ^ comPort)
1339 {
1340 Path = path;
1341 ComPort = comPort;
1342 }
1343
1344 /// <summary>
1345 /// The path descriptor for this CEC adapter
1346 /// </summary>
1347 property System::String ^ Path;
1348
1349 /// <summary>
1350 /// The COM port of this CEC adapter
1351 /// </summary>
1352 property System::String ^ ComPort;
1353 };
1354
1355 /// <summary>
1356 /// A list of CEC device types
1357 /// </summary>
1358 public ref class CecDeviceTypeList
1359 {
1360 public:
1361 /// <summary>
1362 /// Create a new empty list of CEC device types
1363 /// </summary>
1364 CecDeviceTypeList(void)
1365 {
1366 Types = gcnew array<CecDeviceType>(5);
1367 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
1368 Types[iPtr] = CecDeviceType::Reserved;
1369 }
1370
1371 /// <summary>
1372 /// The array with CecDeviceType instances in this list.
1373 /// </summary>
1374 property array<CecDeviceType> ^ Types;
1375 };
1376
1377 /// <summary>
1378 /// A list of logical addresses
1379 /// </summary>
1380 public ref class CecLogicalAddresses
1381 {
1382 public:
1383 /// <summary>
1384 /// Create a new empty list of logical addresses
1385 /// </summary>
1386 CecLogicalAddresses(void)
1387 {
1388 Addresses = gcnew array<CecLogicalAddress>(16);
1389 Clear();
1390 }
1391
1392 /// <summary>
1393 /// Clears this list
1394 /// </summary>
1395 void Clear(void)
1396 {
1397 Primary = CecLogicalAddress::Unknown;
1398 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
1399 Addresses[iPtr] = CecLogicalAddress::Unknown;
1400 }
1401
1402 /// <summary>
1403 /// Checks whether a logical address is set in this list.
1404 /// </summary>
1405 /// <param name="address">The address to check.</param>
1406 /// <returns>True when set, false otherwise</returns>
1407 bool IsSet(CecLogicalAddress address)
1408 {
1409 return Addresses[(unsigned int)address] != CecLogicalAddress::Unknown;
1410 }
1411
1412 /// <summary>
1413 /// Add a logical address to this list (if it's not set already)
1414 /// </summary>
1415 /// <param name="address">The address to add.</param>
1416 void Set(CecLogicalAddress address)
1417 {
1418 Addresses[(unsigned int)address] = address;
1419 if (Primary == CecLogicalAddress::Unknown)
1420 Primary = address;
1421 }
1422
1423 /// <summary>
1424 /// The primary (first) address in this list
1425 /// </summary>
1426 property CecLogicalAddress Primary;
1427
1428 /// <summary>
1429 /// The list of addresses
1430 /// </summary>
1431 property array<CecLogicalAddress> ^ Addresses;
1432 };
1433
1434
1435 /// <summary>
1436 /// Byte array used for CEC command parameters
1437 /// </summary>
1438 public ref class CecDatapacket
1439 {
1440 public:
1441 /// <summary>
1442 /// Create a new byte array with maximum size 100
1443 /// </summary>
1444 CecDatapacket(void)
1445 {
1446 Data = gcnew array<uint8_t>(100);
1447 Size = 0;
1448 }
1449
1450 /// <summary>
1451 /// Adds a byte to this byte array
1452 /// </summary>
1453 /// <param name="data">The byte to add.</param>
1454 void PushBack(uint8_t data)
1455 {
1456 if (Size < 100)
1457 {
1458 Data[Size] = data;
1459 Size++;
1460 }
1461 }
1462
1463 /// <summary>
1464 /// Array data
1465 /// </summary>
1466 property array<uint8_t> ^ Data;
1467
1468 /// <summary>
1469 /// Current data size
1470 /// </summary>
1471 property uint8_t Size;
1472 };
1473
1474 /// <summary>
1475 /// A CEC command that is received or transmitted over the CEC bus
1476 /// </summary>
1477 public ref class CecCommand
1478 {
1479 public:
1480 /// <summary>
1481 /// Create a new CEC command instance
1482 /// </summary>
1483 /// <param name="initiator">The initiator of the command</param>
1484 /// <param name="destination">The receiver of the command</param>
1485 /// <param name="ack">True when the ack bit is set, false otherwise</param>
1486 /// <param name="eom">True when the eom bit is set, false otherwise</param>
1487 /// <param name="opcode">The CEC opcode of this command</param>
1488 /// <param name="transmitTimeout">The timeout to use when transmitting a command</param>
1489 CecCommand(CecLogicalAddress initiator, CecLogicalAddress destination, bool ack, bool eom, CecOpcode opcode, int32_t transmitTimeout)
1490 {
1491 Initiator = initiator;
1492 Destination = destination;
1493 Ack = ack;
1494 Eom = eom;
1495 Opcode = opcode;
1496 OpcodeSet = true;
1497 TransmitTimeout = transmitTimeout;
1498 Parameters = gcnew CecDatapacket;
1499 Empty = false;
1500 }
1501
1502 /// <summary>
1503 /// Create a new empty CEC command instance
1504 /// </summary>
1505 CecCommand(void)
1506 {
1507 Initiator = CecLogicalAddress::Unknown;
1508 Destination = CecLogicalAddress::Unknown;
1509 Ack = false;
1510 Eom = false;
1511 Opcode = CecOpcode::None;
1512 OpcodeSet = false;
1513 TransmitTimeout = 0;
1514 Parameters = gcnew CecDatapacket;
1515 Empty = true;
1516 }
1517
1518 /// <summary>
1519 /// Pushes a byte of data to this CEC command
1520 /// </summary>
1521 /// <param name="data">The byte to add</param>
1522 void PushBack(uint8_t data)
1523 {
1524 if (Initiator == CecLogicalAddress::Unknown && Destination == CecLogicalAddress::Unknown)
1525 {
1526 Initiator = (CecLogicalAddress) (data >> 4);
1527 Destination = (CecLogicalAddress) (data & 0xF);
1528 }
1529 else if (!OpcodeSet)
1530 {
1531 OpcodeSet = true;
1532 Opcode = (CecOpcode)data;
1533 }
1534 else
1535 {
1536 Parameters->PushBack(data);
1537 }
1538 }
1539
1540 /// <summary>
1541 /// True when this command is empty, false otherwise.
1542 /// </summary>
1543 property bool Empty;
1544 /// <summary>
1545 /// The initiator of the command
1546 /// </summary>
1547 property CecLogicalAddress Initiator;
1548 /// <summary>
1549 /// The destination of the command
1550 /// </summary>
1551 property CecLogicalAddress Destination;
1552 /// <summary>
1553 /// True when the ack bit is set, false otherwise
1554 /// </summary>
1555 property bool Ack;
1556 /// <summary>
1557 /// True when the eom bit is set, false otherwise
1558 /// </summary>
1559 property bool Eom;
1560 /// <summary>
1561 /// The CEC opcode of the command
1562 /// </summary>
1563 property CecOpcode Opcode;
1564 /// <summary>
1565 /// The parameters of this command
1566 /// </summary>
1567 property CecDatapacket ^ Parameters;
1568 /// <summary>
1569 /// True when an opcode is set, false otherwise (poll message)
1570 /// </summary>
1571 property bool OpcodeSet;
1572 /// <summary>
1573 /// The timeout to use when transmitting a command
1574 /// </summary>
1575 property int32_t TransmitTimeout;
1576 };
1577
1578 /// <summary>
1579 /// A key press that was received
1580 /// </summary>
1581 public ref class CecKeypress
1582 {
1583 public:
1584 /// <summary>
1585 /// Create a new key press instance
1586 /// </summary>
1587 /// <param name="keycode">The key code of this key press</param>
1588 /// <param name="duration">The duration of this key press in milliseconds</param>
1589 CecKeypress(CecUserControlCode keycode, unsigned int duration)
1590 {
1591 Keycode = keycode;
1592 Duration = duration;
1593 Empty = false;
1594 }
1595
1596 /// <summary>
1597 /// Create a new empty key press instance
1598 /// </summary>
1599 CecKeypress(void)
1600 {
1601 Keycode = CecUserControlCode::Unknown;
1602 Duration = 0;
1603 Empty = true;
1604 }
1605
1606 /// <summary>
1607 /// True when empty, false otherwise
1608 /// </summary>
1609 property bool Empty;
1610 /// <summary>
1611 /// The key code of this key press
1612 /// </summary>
1613 property CecUserControlCode Keycode;
1614 /// <summary>
1615 /// The duration of this key press in milliseconds
1616 /// </summary>
1617 property unsigned int Duration;
1618 };
1619
1620 /// <summary>
1621 /// A log message that libCEC generated
1622 /// </summary>
1623 public ref class CecLogMessage
1624 {
1625 public:
1626 /// <summary>
1627 /// Create a new log message
1628 /// </summary>
1629 /// <param name="message">The actual message</param>
1630 /// <param name="level">The log level, so the application can choose what type information to display</param>
1631 /// <param name="time">The timestamp of this message, in milliseconds after connecting</param>
1632 CecLogMessage(System::String ^ message, CecLogLevel level, int64_t time)
1633 {
1634 Message = message;
1635 Level = level;
1636 Time = time;
1637 Empty = false;
1638 }
1639
1640 /// <summary>
1641 /// Create a new empty log message
1642 /// </summary>
1643 CecLogMessage(void)
1644 {
1645 Message = "";
1646 Level = CecLogLevel::None;
1647 Time = 0;
1648 Empty = true;
1649 }
1650
1651 /// <summary>
1652 /// True when empty, false otherwise.
1653 /// </summary>
1654 property bool Empty;
1655 /// <summary>
1656 /// The actual message
1657 /// </summary>
1658 property System::String ^Message;
1659 /// <summary>
1660 /// The log level, so the application can choose what type information to display
1661 /// </summary>
1662 property CecLogLevel Level;
1663 /// <summary>
1664 /// The timestamp of this message, in milliseconds after connecting
1665 /// </summary>
1666 property int64_t Time;
1667 };
1668
1669 ref class CecCallbackMethods; //forward declaration
1670
1671 /// <summary>
1672 /// The configuration that libCEC uses.
1673 /// </summary>
1674 public ref class LibCECConfiguration
1675 {
1676 public:
1677 /// <summary>
1678 /// Create a new configuration instance with default settings.
1679 /// </summary>
1680 LibCECConfiguration(void)
1681 {
1682 DeviceName = "";
1683 DeviceTypes = gcnew CecDeviceTypeList();
1684 AutodetectAddress = true;
1685 PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
1686 BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE;
1687 HDMIPort = CEC_DEFAULT_HDMI_PORT;
1688 ClientVersion = CecClientVersion::Version2_1_0;
1689 ServerVersion = CecServerVersion::Version2_1_0;
1690 TvVendor = CecVendorId::Unknown;
1691
1692 GetSettingsFromROM = false;
1693 UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1;
1694 ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1;
1695
1696 WakeDevices = gcnew CecLogicalAddresses();
1697 if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1)
1698 WakeDevices->Set(CecLogicalAddress::Tv);
1699
1700 PowerOffDevices = gcnew CecLogicalAddresses();
1701 if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1)
1702 PowerOffDevices->Set(CecLogicalAddress::Broadcast);
1703
1704 PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1;
1705 PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1;
1706
1707 SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1;
1708 LogicalAddresses = gcnew CecLogicalAddresses();
1709 FirmwareVersion = 1;
1710 PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1;
1711 ShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1;
1712 DeviceLanguage = "";
1713 FirmwareBuildDate = gcnew System::DateTime(1970,1,1,0,0,0,0);
1714 CECVersion = (CecVersion)CEC_DEFAULT_SETTING_CEC_VERSION;
1715 AdapterType = CecAdapterType::Unknown;
1716 }
1717
1718 /// <summary>
1719 /// Change the callback method pointers in this configuration instance.
1720 /// </summary>
1721 /// <param name="callbacks">The new callbacks</param>
1722 void SetCallbacks(CecCallbackMethods ^callbacks)
1723 {
1724 Callbacks = callbacks;
1725 }
1726
1727 /// <summary>
1728 /// Update this configuration with data received from libCEC
1729 /// </summary>
1730 /// <param name="config">The configuration that was received from libCEC</param>
1731 void Update(const CEC::libcec_configuration &config)
1732 {
1733 DeviceName = gcnew System::String(config.strDeviceName);
1734
1735 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
1736 DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr];
1737
1738 AutodetectAddress = config.bAutodetectAddress == 1;
1739 PhysicalAddress = config.iPhysicalAddress;
1740 BaseDevice = (CecLogicalAddress)config.baseDevice;
1741 HDMIPort = config.iHDMIPort;
1742 ClientVersion = (CecClientVersion)config.clientVersion;
1743 ServerVersion = (CecServerVersion)config.serverVersion;
1744 TvVendor = (CecVendorId)config.tvVendor;
1745
1746 // player specific settings
1747 GetSettingsFromROM = config.bGetSettingsFromROM == 1;
1748 UseTVMenuLanguage = config.bUseTVMenuLanguage == 1;
1749 ActivateSource = config.bActivateSource == 1;
1750
1751 WakeDevices->Clear();
1752 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
1753 if (config.wakeDevices[iPtr])
1754 WakeDevices->Set((CecLogicalAddress)iPtr);
1755
1756 PowerOffDevices->Clear();
1757 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
1758 if (config.powerOffDevices[iPtr])
1759 PowerOffDevices->Set((CecLogicalAddress)iPtr);
1760
1761 PowerOffScreensaver = config.bPowerOffScreensaver == 1;
1762 PowerOffOnStandby = config.bPowerOffOnStandby == 1;
1763
1764 if (ServerVersion >= CecServerVersion::Version1_5_1)
1765 SendInactiveSource = config.bSendInactiveSource == 1;
1766
1767 if (ServerVersion >= CecServerVersion::Version1_5_3)
1768 {
1769 LogicalAddresses->Clear();
1770 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
1771 if (config.logicalAddresses[iPtr])
1772 LogicalAddresses->Set((CecLogicalAddress)iPtr);
1773 }
1774
1775 if (ServerVersion >= CecServerVersion::Version1_6_0)
1776 {
1777 FirmwareVersion = config.iFirmwareVersion;
1778 PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1;
1779 ShutdownOnStandby = config.bShutdownOnStandby == 1;
1780 }
1781
1782 if (ServerVersion >= CecServerVersion::Version1_6_2)
1783 {
1784 DeviceLanguage = gcnew System::String(config.strDeviceLanguage);
1785 FirmwareBuildDate = gcnew System::DateTime(1970,1,1,0,0,0,0);
1786 FirmwareBuildDate = FirmwareBuildDate->AddSeconds(config.iFirmwareBuildDate);
1787 }
1788
1789 if (ServerVersion >= CecServerVersion::Version1_6_3)
1790 MonitorOnlyClient = config.bMonitorOnly == 1;
1791
1792 if (ServerVersion >= CecServerVersion::Version1_8_0)
1793 CECVersion = (CecVersion)config.cecVersion;
1794
1795 if (ServerVersion >= CecServerVersion::Version1_8_2)
1796 AdapterType = (CecAdapterType)config.adapterType;
1797
1798 if (ServerVersion >= CecServerVersion::Version2_1_0)
1799 PowerOnScreensaver = config.bPowerOnScreensaver == 1;
1800 }
1801
1802 /// <summary>
1803 /// The device name to use on the CEC bus
1804 /// </summary>
1805 property System::String ^ DeviceName;
1806
1807 /// <summary>
1808 /// The device type(s) to use on the CEC bus for libCEC
1809 /// </summary>
1810 property CecDeviceTypeList ^ DeviceTypes;
1811
1812 /// <summary>
1813 /// (read only) set to true by libCEC when the physical address was autodetected
1814 /// </summary>
1815 property bool AutodetectAddress;
1816
1817 /// <summary>
1818 /// The physical address of the CEC adapter
1819 /// </summary>
1820 property uint16_t PhysicalAddress;
1821
1822 /// <summary>
1823 /// 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
1824 /// </summary>
1825 property CecLogicalAddress BaseDevice;
1826
1827 /// <summary>
1828 /// The HDMI port to which the adapter is connected. Only used when iPhysicalAddress = 0 or when the adapter doesn't support autodetection
1829 /// </summary>
1830 property uint8_t HDMIPort;
1831
1832 /// <summary>
1833 /// The client API version to use
1834 /// </summary>
1835 property CecClientVersion ClientVersion;
1836
1837 /// <summary>
1838 /// The version of libCEC
1839 /// </summary>
1840 property CecServerVersion ServerVersion;
1841
1842 /// <summary>
1843 /// Override the vendor ID of the TV. Leave this untouched to autodetect
1844 /// </summary>
1845 property CecVendorId TvVendor;
1846
1847 /// <summary>
1848 /// True to read the settings from the EEPROM, which possibly override the settings passed here
1849 /// </summary>
1850 property bool GetSettingsFromROM;
1851
1852 /// <summary>
1853 /// Use the language setting of the TV in the client application. Must be implemented by the client application.
1854 /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/
1855 /// </summary>
1856 property bool UseTVMenuLanguage;
1857
1858 /// <summary>
1859 /// Make libCEC the active source when starting the client application
1860 /// </summary>
1861 property bool ActivateSource;
1862
1863 /// <summary>
1864 /// List of devices to wake when initialising libCEC or when calling PowerOnDevices() without any parameter.
1865 /// </summary>
1866 property CecLogicalAddresses ^WakeDevices;
1867
1868 /// <summary>
1869 /// List of devices to power off when calling StandbyDevices() without any parameter.
1870 /// </summary>
1871 property CecLogicalAddresses ^PowerOffDevices;
1872
1873 /// <summary>
1874 /// Send standby commands when the client application activates the screensaver. Must be implemented by the client application.
1875 /// </summary>
1876 property bool PowerOffScreensaver;
1877
1878 /// <summary>
1879 /// Power off the PC when the TV powers off. Must be implemented by the client application.
1880 /// </summary>
1881 property bool PowerOffOnStandby;
1882
1883 /// <summary>
1884 /// Send an inactive source message when exiting the client application.
1885 /// </summary>
1886 property bool SendInactiveSource;
1887
1888 /// <summary>
1889 /// The list of logical addresses that libCEC is using
1890 /// </summary>
1891 property CecLogicalAddresses ^LogicalAddresses;
1892
1893 /// <summary>
1894 /// The firmware version of the adapter to which libCEC is connected
1895 /// </summary>
1896 property uint16_t FirmwareVersion;
1897
1898 /// <summary>
1899 /// Send standby commands when the client application activates standby mode (S3). Must be implemented by the client application.
1900 /// </summary>
1901 property bool PowerOffDevicesOnStandby;
1902
1903 /// <summary>
1904 /// Shutdown this PC when the TV is switched off. only used when PowerOffOnStandby = false
1905 /// </summary>
1906 property bool ShutdownOnStandby;
1907
1908 /// <summary>
1909 /// True to start a monitor-only client, false to start a standard client.
1910 /// </summary>
1911 property bool MonitorOnlyClient;
1912
1913 /// <summary>
1914 /// The language code of the menu language that libCEC reports to other devices.
1915 /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/
1916 /// </summary>
1917 property System::String ^ DeviceLanguage;
1918
1919 /// <summary>
1920 /// The callback methods to use.
1921 /// </summary>
1922 property CecCallbackMethods ^ Callbacks;
1923
1924 /// <summary>
1925 /// The build date of the firmware.
1926 /// </summary>
1927 property System::DateTime ^ FirmwareBuildDate;
1928
1929 /// <summary>
1930 /// The CEC version that libCEC uses.
1931 /// </summary>
1932 property CecVersion CECVersion;
1933
1934 /// <summary>
1935 /// The type of adapter that libCEC is connected to.
1936 /// </summary>
1937 property CecAdapterType AdapterType;
1938 };
1939
1940 // the callback methods are called by unmanaged code, so we need some delegates for this
1941 #pragma unmanaged
1942 // unmanaged callback methods
1943 typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message);
1944 typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key);
1945 typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command);
1946 typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config);
1947 typedef int (__stdcall *ALERTCB) (const CEC::libcec_alert, const CEC::libcec_parameter &data);
1948 typedef int (__stdcall *MENUCB) (const CEC::cec_menu_state newVal);
1949 typedef void (__stdcall *ACTICB) (const CEC::cec_logical_address logicalAddress, const uint8_t bActivated);
1950
1951 /// <summary>
1952 /// libCEC callback methods. Unmanaged code.
1953 /// </summary>
1954 typedef struct
1955 {
1956 /// <summary>
1957 /// Log message callback
1958 /// </summary>
1959 LOGCB logCB;
1960 /// <summary>
1961 /// Key press/release callback
1962 /// </summary>
1963 KEYCB keyCB;
1964 /// <summary>
1965 /// Raw CEC data callback
1966 /// </summary>
1967 COMMANDCB commandCB;
1968 /// <summary>
1969 /// Updated configuration callback
1970 /// </summary>
1971 CONFIGCB configCB;
1972 /// <summary>
1973 /// Alert message callback
1974 /// </summary>
1975 ALERTCB alertCB;
1976 /// <summary>
1977 /// Menu status change callback
1978 /// </summary>
1979 MENUCB menuCB;
1980 /// <summary>
1981 /// Source (de)activated callback
1982 /// </summary>
1983 ACTICB sourceActivatedCB;
1984 } UnmanagedCecCallbacks;
1985
1986 static PLATFORM::CMutex g_callbackMutex;
1987 static std::vector<UnmanagedCecCallbacks> g_unmanagedCallbacks;
1988 static CEC::ICECCallbacks g_cecCallbacks;
1989
1990 /// <summary>
1991 /// Called by libCEC to send back a log message to the application
1992 /// </summary>
1993 /// <param name="cbParam">Pointer to the callback struct</param>
1994 /// <param name="message">The log message</param>
1995 /// <return>1 when handled, 0 otherwise</return>
1996 int CecLogMessageCB(void *cbParam, const CEC::cec_log_message message)
1997 {
1998 if (cbParam)
1999 {
2000 size_t iPtr = (size_t)cbParam;
2001 PLATFORM::CLockObject lock(g_callbackMutex);
2002 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
2003 return g_unmanagedCallbacks[iPtr].logCB(message);
2004 }
2005 return 0;
2006 }
2007
2008 /// <summary>
2009 /// Called by libCEC to send back a key press or release to the application
2010 /// </summary>
2011 /// <param name="cbParam">Pointer to the callback struct</param>
2012 /// <param name="key">The key press command that libCEC received</param>
2013 /// <return>1 when handled, 0 otherwise</return>
2014 int CecKeyPressCB(void *cbParam, const CEC::cec_keypress key)
2015 {
2016 if (cbParam)
2017 {
2018 size_t iPtr = (size_t)cbParam;
2019 PLATFORM::CLockObject lock(g_callbackMutex);
2020 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
2021 return g_unmanagedCallbacks[iPtr].keyCB(key);
2022 }
2023 return 0;
2024 }
2025
2026 /// <summary>
2027 /// Called by libCEC to send back raw CEC data to the application
2028 /// </summary>
2029 /// <param name="cbParam">Pointer to the callback struct</param>
2030 /// <param name="command">The raw CEC data</param>
2031 /// <return>1 when handled, 0 otherwise</return>
2032 int CecCommandCB(void *cbParam, const CEC::cec_command command)
2033 {
2034 if (cbParam)
2035 {
2036 size_t iPtr = (size_t)cbParam;
2037 PLATFORM::CLockObject lock(g_callbackMutex);
2038 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
2039 return g_unmanagedCallbacks[iPtr].commandCB(command);
2040 }
2041 return 0;
2042 }
2043
2044 /// <summary>
2045 /// Called by libCEC to send back an updated configuration to the application
2046 /// </summary>
2047 /// <param name="cbParam">Pointer to the callback struct</param>
2048 /// <param name="config">The new configuration</param>
2049 /// <return>1 when handled, 0 otherwise</return>
2050 int CecConfigCB(void *cbParam, const CEC::libcec_configuration config)
2051 {
2052 if (cbParam)
2053 {
2054 size_t iPtr = (size_t)cbParam;
2055 PLATFORM::CLockObject lock(g_callbackMutex);
2056 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
2057 return g_unmanagedCallbacks[iPtr].configCB(config);
2058 }
2059 return 0;
2060 }
2061
2062 /// <summary>
2063 /// Called by libCEC to send back an alert message to the application
2064 /// </summary>
2065 /// <param name="cbParam">Pointer to the callback struct</param>
2066 /// <param name="data">The alert message</param>
2067 /// <return>1 when handled, 0 otherwise</return>
2068 int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter data)
2069 {
2070 if (cbParam)
2071 {
2072 size_t iPtr = (size_t)cbParam;
2073 PLATFORM::CLockObject lock(g_callbackMutex);
2074 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
2075 return g_unmanagedCallbacks[iPtr].alertCB(alert, data);
2076 }
2077 return 0;
2078 }
2079
2080 /// <summary>
2081 /// Called by libCEC to send back a menu state change to the application
2082 /// </summary>
2083 /// <param name="cbParam">Pointer to the callback struct</param>
2084 /// <param name="newVal">The new menu state</param>
2085 /// <return>1 when handled, 0 otherwise</return>
2086 int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal)
2087 {
2088 if (cbParam)
2089 {
2090 size_t iPtr = (size_t)cbParam;
2091 PLATFORM::CLockObject lock(g_callbackMutex);
2092 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
2093 return g_unmanagedCallbacks[iPtr].menuCB(newVal);
2094 }
2095 return 0;
2096 }
2097
2098 /// <summary>
2099 /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated
2100 /// </summary>
2101 /// <param name="cbParam">Pointer to the callback struct</param>
2102 /// <param name="logicalAddress">The logical address that was (de)activated</param>
2103 /// <param name="activated">True when activated, false when deactivated</param>
2104 void CecSourceActivatedCB(void *cbParam, const CEC::cec_logical_address logicalAddress, const uint8_t activated)
2105 {
2106 if (cbParam)
2107 {
2108 size_t iPtr = (size_t)cbParam;
2109 PLATFORM::CLockObject lock(g_callbackMutex);
2110 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
2111 g_unmanagedCallbacks[iPtr].sourceActivatedCB(logicalAddress, activated);
2112 }
2113 }
2114
2115 #pragma managed
2116 /// <summary>
2117 /// Delegate method for the CecLogMessageCB callback in CecCallbackMethods
2118 /// </summary>
2119 public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &);
2120 /// <summary>
2121 /// Delegate method for the CecKeyPressCB callback in CecCallbackMethods
2122 /// </summary>
2123 public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &);
2124 /// <summary>
2125 /// Delegate method for the CecCommandCB callback in CecCallbackMethods
2126 /// </summary>
2127 public delegate int CecCommandManagedDelegate(const CEC::cec_command &);
2128 /// <summary>
2129 /// Delegate method for the CecConfigCB callback in CecCallbackMethods
2130 /// </summary>
2131 public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &);
2132 /// <summary>
2133 /// Delegate method for the CecAlertCB callback in CecCallbackMethods
2134 /// </summary>
2135 public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &);
2136 /// <summary>
2137 /// Delegate method for the CecMenuCB callback in CecCallbackMethods
2138 /// </summary>
2139 public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state);
2140 /// <summary>
2141 /// Delegate method for the CecSourceActivatedCB callback in CecCallbackMethods
2142 /// </summary>
2143 public delegate void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address, const uint8_t);
2144
2145 /// <summary>
2146 /// Assign the callback methods in the g_cecCallbacks struct
2147 /// </summary>
2148 void AssignCallbacks()
2149 {
2150 g_cecCallbacks.CBCecLogMessage = CecLogMessageCB;
2151 g_cecCallbacks.CBCecKeyPress = CecKeyPressCB;
2152 g_cecCallbacks.CBCecCommand = CecCommandCB;
2153 g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB;
2154 g_cecCallbacks.CBCecAlert = CecAlertCB;
2155 g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB;
2156 g_cecCallbacks.CBCecSourceActivated = CecSourceActivatedCB;
2157 }
2158
2159 /// <summary>
2160 /// The callback methods that libCEC uses
2161 /// </summary>
2162 public ref class CecCallbackMethods
2163 {
2164 public:
2165 CecCallbackMethods(void)
2166 {
2167 m_iCallbackPtr = -1;
2168 AssignCallbacks();
2169 m_bHasCallbacks = false;
2170 m_bDelegatesCreated = false;
2171 }
2172
2173 ~CecCallbackMethods(void)
2174 {
2175 DestroyDelegates();
2176 }
2177
2178 /// <summary>
2179 /// Pointer to the callbacks struct entry
2180 /// </summary>
2181 size_t GetCallbackPtr(void)
2182 {
2183 PLATFORM::CLockObject lock(g_callbackMutex);
2184 return m_iCallbackPtr;
2185 }
2186
2187 protected:
2188 !CecCallbackMethods(void)
2189 {
2190 DestroyDelegates();
2191 }
2192
2193 public:
2194 /// <summary>
2195 /// Disable callback methods
2196 /// </summary>
2197 virtual void DisableCallbacks(void)
2198 {
2199 DestroyDelegates();
2200 }
2201
2202 /// <summary>
2203 /// Enable callback methods
2204 /// </summary>
2205 /// <param name="callbacks">Callback methods to activate</param>
2206 /// <return>true when handled, false otherwise</return>
2207 virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks)
2208 {
2209 CreateDelegates();
2210 if (!m_bHasCallbacks)
2211 {
2212 m_bHasCallbacks = true;
2213 m_callbacks = callbacks;
2214 return true;
2215 }
2216
2217 return false;
2218 }
2219
2220 /// <summary>
2221 /// Called by libCEC to send back a log message to the application.
2222 /// Override in the application to handle this callback.
2223 /// </summary>
2224 /// <param name="message">The log message</param>
2225 /// <return>1 when handled, 0 otherwise</return>
2226 virtual int ReceiveLogMessage(CecLogMessage ^ message)
2227 {
2228 return 0;
2229 }
2230
2231 /// <summary>
2232 /// Called by libCEC to send back a key press or release to the application.
2233 /// Override in the application to handle this callback.
2234 /// </summary>
2235 /// <param name="key">The key press command that libCEC received</param>
2236 /// <return>1 when handled, 0 otherwise</return>
2237 virtual int ReceiveKeypress(CecKeypress ^ key)
2238 {
2239 return 0;
2240 }
2241
2242 /// <summary>
2243 /// Called by libCEC to send back raw CEC data to the application.
2244 /// Override in the application to handle this callback.
2245 /// </summary>
2246 /// <param name="command">The raw CEC data</param>
2247 /// <return>1 when handled, 0 otherwise</return>
2248 virtual int ReceiveCommand(CecCommand ^ command)
2249 {
2250 return 0;
2251 }
2252
2253 /// <summary>
2254 /// Called by libCEC to send back an updated configuration to the application.
2255 /// Override in the application to handle this callback.
2256 /// </summary>
2257 /// <param name="config">The new configuration</param>
2258 /// <return>1 when handled, 0 otherwise</return>
2259 virtual int ConfigurationChanged(LibCECConfiguration ^ config)
2260 {
2261 return 0;
2262 }
2263
2264 /// <summary>
2265 /// Called by libCEC to send back an alert message to the application.
2266 /// Override in the application to handle this callback.
2267 /// </summary>
2268 /// <param name="data">The alert message</param>
2269 /// <return>1 when handled, 0 otherwise</return>
2270 virtual int ReceiveAlert(CecAlert alert, CecParameter ^ data)
2271 {
2272 return 0;
2273 }
2274
2275 /// <summary>
2276 /// Called by libCEC to send back a menu state change to the application.
2277 /// Override in the application to handle this callback.
2278 /// </summary>
2279 /// <param name="newVal">The new menu state</param>
2280 /// <return>1 when handled, 0 otherwise</return>
2281 virtual int ReceiveMenuStateChange(CecMenuState newVal)
2282 {
2283 return 0;
2284 }
2285
2286 /// <summary>
2287 /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated.
2288 /// Override in the application to handle this callback.
2289 /// </summary>
2290 /// <param name="logicalAddress">The logical address that was (de)activated</param>
2291 /// <param name="activated">True when activated, false when deactivated</param>
2292 virtual void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
2293 {
2294 }
2295
2296 protected:
2297 // managed callback methods
2298 int CecLogMessageManaged(const CEC::cec_log_message &message)
2299 {
2300 int iReturn(0);
2301 if (m_bHasCallbacks)
2302 iReturn = m_callbacks->ReceiveLogMessage(gcnew CecLogMessage(gcnew System::String(message.message), (CecLogLevel)message.level, message.time));
2303 return iReturn;
2304 }
2305
2306 int CecKeyPressManaged(const CEC::cec_keypress &key)
2307 {
2308 int iReturn(0);
2309 if (m_bHasCallbacks)
2310 iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration));
2311 return iReturn;
2312 }
2313
2314 int CecCommandManaged(const CEC::cec_command &command)
2315 {
2316 int iReturn(0);
2317 if (m_bHasCallbacks)
2318 {
2319 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);
2320 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
2321 newCommand->Parameters->PushBack(command.parameters[iPtr]);
2322 iReturn = m_callbacks->ReceiveCommand(newCommand);
2323 }
2324 return iReturn;
2325 }
2326
2327 int CecConfigManaged(const CEC::libcec_configuration &config)
2328 {
2329 int iReturn(0);
2330 if (m_bHasCallbacks)
2331 {
2332 LibCECConfiguration ^netConfig = gcnew LibCECConfiguration();
2333 netConfig->Update(config);
2334 iReturn = m_callbacks->ConfigurationChanged(netConfig);
2335 }
2336 return iReturn;
2337 }
2338
2339 int CecAlertManaged(const CEC::libcec_alert alert, const CEC::libcec_parameter &data)
2340 {
2341 int iReturn(0);
2342 if (m_bHasCallbacks)
2343 {
2344 CecParameterType newType = (CecParameterType)data.paramType;
2345 if (newType == CecParameterType::ParameterTypeString)
2346 {
2347 System::String ^ newData = gcnew System::String((const char *)data.paramData, 0, 128);
2348 CecParameter ^ newParam = gcnew CecParameter(newType, newData);
2349 iReturn = m_callbacks->ReceiveAlert((CecAlert)alert, newParam);
2350 }
2351 }
2352 return iReturn;
2353 }
2354
2355 int CecMenuManaged(const CEC::cec_menu_state newVal)
2356 {
2357 int iReturn(0);
2358 if (m_bHasCallbacks)
2359 {
2360 iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal);
2361 }
2362 return iReturn;
2363 }
2364
2365 void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated)
2366 {
2367 if (m_bHasCallbacks)
2368 m_callbacks->SourceActivated((CecLogicalAddress)logicalAddress, bActivated == 1);
2369 }
2370
2371 void DestroyDelegates()
2372 {
2373 m_bHasCallbacks = false;
2374 if (m_bDelegatesCreated)
2375 {
2376 m_bDelegatesCreated = false;
2377 m_logMessageGCHandle.Free();
2378 m_keypressGCHandle.Free();
2379 m_commandGCHandle.Free();
2380 m_alertGCHandle.Free();
2381 m_menuGCHandle.Free();
2382 m_sourceActivatedGCHandle.Free();
2383 }
2384 }
2385
2386 void CreateDelegates()
2387 {
2388 DestroyDelegates();
2389
2390 if (!m_bDelegatesCreated)
2391 {
2392 msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context();
2393
2394 // create the delegate method for the log message callback
2395 m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged);
2396 m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate);
2397 m_logMessageCallback = static_cast<LOGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer());
2398
2399 // create the delegate method for the keypress callback
2400 m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged);
2401 m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate);
2402 m_keypressCallback = static_cast<KEYCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer());
2403
2404 // create the delegate method for the command callback
2405 m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged);
2406 m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate);
2407 m_commandCallback = static_cast<COMMANDCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer());
2408
2409 // create the delegate method for the configuration change callback
2410 m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged);
2411 m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate);
2412 m_configCallback = static_cast<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer());
2413
2414 // create the delegate method for the alert callback
2415 m_alertDelegate = gcnew CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged);
2416 m_alertGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate);
2417 m_alertCallback = static_cast<ALERTCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer());
2418
2419 // create the delegate method for the menu callback
2420 m_menuDelegate = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged);
2421 m_menuGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate);
2422 m_menuCallback = static_cast<MENUCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer());
2423
2424 // create the delegate method for the source activated callback
2425 m_sourceActivatedDelegate = gcnew CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged);
2426 m_sourceActivatedGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate);
2427 m_sourceActivatedCallback = static_cast<ACTICB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate).ToPointer());
2428
2429 delete context;
2430
2431 UnmanagedCecCallbacks unmanagedCallbacks;
2432 unmanagedCallbacks.logCB = m_logMessageCallback;
2433 unmanagedCallbacks.keyCB = m_keypressCallback;
2434 unmanagedCallbacks.commandCB = m_commandCallback;
2435 unmanagedCallbacks.configCB = m_configCallback;
2436 unmanagedCallbacks.alertCB = m_alertCallback;
2437 unmanagedCallbacks.menuCB = m_menuCallback;
2438 unmanagedCallbacks.sourceActivatedCB = m_sourceActivatedCallback;
2439
2440 PLATFORM::CLockObject lock(g_callbackMutex);
2441 g_unmanagedCallbacks.push_back(unmanagedCallbacks);
2442 m_iCallbackPtr = g_unmanagedCallbacks.size() - 1;
2443 m_bDelegatesCreated = true;
2444 }
2445 }
2446
2447 CecLogMessageManagedDelegate ^ m_logMessageDelegate;
2448 static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle;
2449 LOGCB m_logMessageCallback;
2450
2451 CecKeyPressManagedDelegate ^ m_keypressDelegate;
2452 static System::Runtime::InteropServices::GCHandle m_keypressGCHandle;
2453 KEYCB m_keypressCallback;
2454
2455 CecCommandManagedDelegate ^ m_commandDelegate;
2456 static System::Runtime::InteropServices::GCHandle m_commandGCHandle;
2457 COMMANDCB m_commandCallback;
2458
2459 CecConfigManagedDelegate ^ m_configDelegate;
2460 static System::Runtime::InteropServices::GCHandle m_configGCHandle;
2461 CONFIGCB m_configCallback;
2462
2463 CecAlertManagedDelegate ^ m_alertDelegate;
2464 static System::Runtime::InteropServices::GCHandle m_alertGCHandle;
2465 ALERTCB m_alertCallback;
2466
2467 CecMenuManagedDelegate ^ m_menuDelegate;
2468 static System::Runtime::InteropServices::GCHandle m_menuGCHandle;
2469 MENUCB m_menuCallback;
2470
2471 CecSourceActivatedManagedDelegate ^ m_sourceActivatedDelegate;
2472 static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle;
2473 ACTICB m_sourceActivatedCallback;
2474
2475 CecCallbackMethods ^ m_callbacks;
2476 bool m_bHasCallbacks;
2477 bool m_bDelegatesCreated;
2478 size_t m_iCallbackPtr;
2479 };
2480 }