updated changelog for 1.9.0
[deb_libcec.git] / src / LibCecSharp / CecSharpTypes.h
CommitLineData
4ef3b314
LOK
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
dc6366e8 34#include "../lib/platform/threads/mutex.h"
4ef3b314
LOK
35#include <vcclr.h>
36#include <msclr/marshal.h>
37#include "../../include/cec.h"
dc6366e8 38#include <vector>
4ef3b314
LOK
39
40#using <System.dll>
41
42namespace CecSharp
43{
44 public enum class CecDeviceType
45 {
46 Tv = 0,
47 RecordingDevice = 1,
48 Reserved = 2,
49 Tuner = 3,
50 PlaybackDevice = 4,
51 AudioSystem = 5
52 };
53
54 public enum class CecLogLevel
55 {
56 None = 0,
57 Error = 1,
58 Warning = 2,
59 Notice = 4,
60 Traffic = 8,
61 Debug = 16,
62 All = 31
63 };
64
65 public enum class CecLogicalAddress
66 {
67 Unknown = -1, //not a valid logical address
68 Tv = 0,
69 RecordingDevice1 = 1,
70 RecordingDevice2 = 2,
71 Tuner1 = 3,
72 PlaybackDevice1 = 4,
73 AudioSystem = 5,
74 Tuner2 = 6,
75 Tuner3 = 7,
76 PlaybackDevice2 = 8,
77 RecordingDevice3 = 9,
78 Tuner4 = 10,
79 PlaybackDevice3 = 11,
80 Reserved1 = 12,
81 Reserved2 = 13,
82 FreeUse = 14,
83 Unregistered = 15,
84 Broadcast = 15
85 };
86
6e919697
MK
87 public enum class CecAlert
88 {
89 ServiceDevice = 1
90 };
91
92 public enum class CecParameterType
93 {
94 ParameterTypeString = 1
95 };
96
97 public ref class CecParameter
98 {
99 public:
100 CecParameter(CecParameterType type, System::String ^ strData)
101 {
102 Type = type;
103 Data = strData;
104 }
105
106 property CecParameterType Type;
107 property System::String ^ Data;
108 };
109
4ef3b314
LOK
110 public enum class CecPowerStatus
111 {
112 On = 0x00,
113 Standby = 0x01,
114 InTransitionStandbyToOn = 0x02,
115 InTransitionOnToStandby = 0x03,
116 Unknown = 0x99
117 };
118
119 public enum class CecVersion
120 {
121 Unknown = 0x00,
122 V1_2 = 0x01,
123 V1_2A = 0x02,
124 V1_3 = 0x03,
125 V1_3A = 0x04,
126 V1_4 = 0x05
127 };
128
129 public enum class CecDisplayControl
130 {
131 DisplayForDefaultTime = 0x00,
132 DisplayUntilCleared = 0x40,
133 ClearPreviousMessage = 0x80,
134 ReservedForFutureUse = 0xC0
135 };
136
137 public enum class CecMenuState
138 {
139 Activated = 0,
140 Deactivated = 1
141 };
142
143 public enum class CecDeckControlMode
144 {
145 SkipForwardWind = 1,
146 SkipReverseRewind = 2,
147 Stop = 3,
148 Eject = 4
149 };
150
151 public enum class CecDeckInfo
152 {
153 Play = 0x11,
154 Record = 0x12,
155 Reverse = 0x13,
156 Still = 0x14,
157 Slow = 0x15,
158 SlowReverse = 0x16,
159 FastForward = 0x17,
160 FastReverse = 0x18,
161 NoMedia = 0x19,
162 Stop = 0x1A,
163 SkipForwardWind = 0x1B,
164 SkipReverseRewind = 0x1C,
165 IndexSearchForward = 0x1D,
166 IndexSearchReverse = 0x1E,
167 OtherStatus = 0x1F
168 };
169
170 public enum class CecUserControlCode
171 {
172 Select = 0x00,
173 Up = 0x01,
174 Down = 0x02,
175 Left = 0x03,
176 Right = 0x04,
177 RightUp = 0x05,
178 RightDown = 0x06,
179 LeftUp = 0x07,
180 LeftDown = 0x08,
181 RootMenu = 0x09,
182 SetupMenu = 0x0A,
183 ContentsMenu = 0x0B,
184 FavoriteMenu = 0x0C,
185 Exit = 0x0D,
186 Number0 = 0x20,
187 Number1 = 0x21,
188 Number2 = 0x22,
189 Number3 = 0x23,
190 Number4 = 0x24,
191 Number5 = 0x25,
192 Number6 = 0x26,
193 Number7 = 0x27,
194 Number8 = 0x28,
195 Number9 = 0x29,
196 Dot = 0x2A,
197 Enter = 0x2B,
198 Clear = 0x2C,
199 NextFavorite = 0x2F,
200 ChannelUp = 0x30,
201 ChannelDown = 0x31,
202 PreviousChannel = 0x32,
203 SoundSelect = 0x33,
204 InputSelect = 0x34,
205 DisplayInformation = 0x35,
206 Help = 0x36,
207 PageUp = 0x37,
208 PageDown = 0x38,
209 Power = 0x40,
210 VolumeUp = 0x41,
211 VolumeDown = 0x42,
212 Mute = 0x43,
213 Play = 0x44,
214 Stop = 0x45,
215 Pause = 0x46,
216 Record = 0x47,
217 Rewind = 0x48,
218 FastForward = 0x49,
219 Eject = 0x4A,
220 Forward = 0x4B,
221 Backward = 0x4C,
222 StopRecord = 0x4D,
223 PauseRecord = 0x4E,
224 Angle = 0x50,
225 SubPicture = 0x51,
226 VideoOnDemand = 0x52,
227 ElectronicProgramGuide = 0x53,
228 TimerProgramming = 0x54,
229 InitialConfiguration = 0x55,
230 PlayFunction = 0x60,
231 PausePlayFunction = 0x61,
232 RecordFunction = 0x62,
233 PauseRecordFunction = 0x63,
234 StopFunction = 0x64,
235 MuteFunction = 0x65,
236 RestoreVolumeFunction = 0x66,
237 TuneFunction = 0x67,
238 SelectMediaFunction = 0x68,
239 SelectAVInputFunction = 0x69,
240 SelectAudioInputFunction = 0x6A,
241 PowerToggleFunction = 0x6B,
242 PowerOffFunction = 0x6C,
243 PowerOnFunction = 0x6D,
244 F1Blue = 0x71,
245 F2Red = 0X72,
246 F3Green = 0x73,
247 F4Yellow = 0x74,
248 F5 = 0x75,
249 Data = 0x76,
250 Max = 0x76,
04be3a97 251 SamsungReturn = 0x91,
4ef3b314
LOK
252 Unknown
253 };
254
255 public enum class CecVendorId
256 {
23d38eec
LOK
257 Samsung = 0x0000F0,
258 LG = 0x00E091,
259 Panasonic = 0x008045,
260 Pioneer = 0x00E036,
261 Onkyo = 0x0009B0,
262 Yamaha = 0x00A0DE,
263 Philips = 0x00903E,
de90f347 264 Sony = 0x080046,
23d38eec
LOK
265 Toshiba = 0x000039,
266 Akai = 0x0020C7,
267 Benq = 0x8065E9,
268 Daewoo = 0x009053,
269 Grundig = 0x00D0D5,
270 Medion = 0x000CB8,
271 Sharp = 0x08001F,
8dd7087c 272 Vizio = 0x6B746D,
4ef3b314
LOK
273 Unknown = 0
274 };
275
276 public enum class CecAudioStatus
277 {
278 MuteStatusMask = 0x80,
279 VolumeStatusMask = 0x7F,
280 VolumeMin = 0x00,
281 VolumeMax = 0x64,
282 VolumeStatusUnknown = 0x7F
283 };
284
285 public enum class CecOpcode
286 {
287 ActiveSource = 0x82,
288 ImageViewOn = 0x04,
289 TextViewOn = 0x0D,
290 InactiveSource = 0x9D,
291 RequestActiveSource = 0x85,
292 RoutingChange = 0x80,
293 RoutingInformation = 0x81,
294 SetStreamPath = 0x86,
295 Standby = 0x36,
296 RecordOff = 0x0B,
297 RecordOn = 0x09,
298 RecordStatus = 0x0A,
299 RecordTvScreen = 0x0F,
300 ClearAnalogueTimer = 0x33,
301 ClearDigitalTimer = 0x99,
302 ClearExternalTimer = 0xA1,
303 SetAnalogueTimer = 0x34,
304 SetDigitalTimer = 0x97,
305 SetExternalTimer = 0xA2,
306 SetTimerProgramTitle = 0x67,
307 TimerClearedStatus = 0x43,
308 TimerStatus = 0x35,
309 CecVersion = 0x9E,
310 GetCecVersion = 0x9F,
311 GivePhysicalAddress = 0x83,
312 GetMenuLanguage = 0x91,
313 ReportPhysicalAddress = 0x84,
314 SetMenuLanguage = 0x32,
315 DeckControl = 0x42,
316 DeckStatus = 0x1B,
317 GiveDeckStatus = 0x1A,
318 Play = 0x41,
319 GiveTunerDeviceStatus = 0x08,
320 SelectAnalogueService = 0x92,
321 SelectDigtalService = 0x93,
322 TunerDeviceStatus = 0x07,
323 TunerStepDecrement = 0x06,
324 TunerStepIncrement = 0x05,
325 DeviceVendorId = 0x87,
326 GiveDeviceVendorId = 0x8C,
327 VendorCommand = 0x89,
328 VendorCommandWithId = 0xA0,
329 VendorRemoteButtonDown = 0x8A,
330 VendorRemoteButtonUp = 0x8B,
331 SetOsdString = 0x64,
332 GiveOsdName = 0x46,
333 SetOsdName = 0x47,
334 MenuRequest = 0x8D,
335 MenuStatus = 0x8E,
336 UserControlPressed = 0x44,
337 UserControlRelease = 0x45,
338 GiveDevicePowerStatus = 0x8F,
339 ReportPowerStatus = 0x90,
340 FeatureAbort = 0x00,
341 Abort = 0xFF,
342 GiveAudioStatus = 0x71,
343 GiveSystemAudioMode = 0x7D,
344 ReportAudioStatus = 0x7A,
345 SetSystemAudioMode = 0x72,
346 SystemAudioModeRequest = 0x70,
347 SystemAudioModeStatus = 0x7E,
348 SetAudioRate = 0x9A,
349 /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */
350 None = 0xFD
351 };
352
353 public enum class CecSystemAudioStatus
354 {
355 Off = 0,
356 On = 1
357 };
358
359 public enum class CecClientVersion
360 {
361 VersionPre1_5 = 0,
a8fffd1b 362 Version1_5_0 = 0x1500,
e4a7396c
LOK
363 Version1_5_1 = 0x1501,
364 Version1_5_2 = 0x1502,
365 Version1_5_3 = 0x1503,
366 Version1_6_0 = 0x1600,
6d0364f9 367 Version1_6_1 = 0x1601,
c2ce7bd1
LOK
368 Version1_6_2 = 0x1602,
369 Version1_6_3 = 0x1603,
370 Version1_7_0 = 0x1700,
2b44051c
LOK
371 Version1_7_1 = 0x1701,
372 Version1_7_2 = 0x1702,
7e316a2f
LOK
373 Version1_8_0 = 0x1800,
374 Version1_8_1 = 0x1801
4ef3b314
LOK
375 };
376
e4a7396c 377 public enum class CecServerVersion
3efda01a
LOK
378 {
379 VersionPre1_5 = 0,
a8fffd1b 380 Version1_5_0 = 0x1500,
e4a7396c
LOK
381 Version1_5_1 = 0x1501,
382 Version1_5_2 = 0x1502,
383 Version1_5_3 = 0x1503,
384 Version1_6_0 = 0x1600,
6d0364f9 385 Version1_6_1 = 0x1601,
c2ce7bd1
LOK
386 Version1_6_2 = 0x1602,
387 Version1_6_3 = 0x1603,
388 Version1_7_0 = 0x1700,
2b44051c
LOK
389 Version1_7_1 = 0x1701,
390 Version1_7_2 = 0x1702,
7e316a2f
LOK
391 Version1_8_0 = 0x1800,
392 Version1_8_1 = 0x1801
3efda01a
LOK
393 };
394
4ef3b314
LOK
395 public ref class CecAdapter
396 {
397 public:
398 CecAdapter(System::String ^ strPath, System::String ^ strComPort)
399 {
400 Path = strPath;
401 ComPort = strComPort;
402 }
403
404 property System::String ^ Path;
405 property System::String ^ ComPort;
406 };
407
408 public ref class CecDeviceTypeList
409 {
410 public:
411 CecDeviceTypeList(void)
412 {
413 Types = gcnew array<CecDeviceType>(5);
414 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
415 Types[iPtr] = CecDeviceType::Reserved;
416 }
417
418 property array<CecDeviceType> ^ Types;
419 };
420
421 public ref class CecLogicalAddresses
422 {
423 public:
424 CecLogicalAddresses(void)
425 {
426 Addresses = gcnew array<CecLogicalAddress>(16);
b7907707
LOK
427 Clear();
428 }
429
430 void Clear(void)
431 {
2b44051c 432 Primary = CecLogicalAddress::Unknown;
4ef3b314 433 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
63851508 434 Addresses[iPtr] = CecLogicalAddress::Unknown;
4ef3b314
LOK
435 }
436
437 bool IsSet(CecLogicalAddress iAddress)
438 {
63851508 439 return Addresses[(unsigned int)iAddress] != CecLogicalAddress::Unknown;
4ef3b314
LOK
440 }
441
b7907707
LOK
442 void Set(CecLogicalAddress iAddress)
443 {
444 Addresses[(unsigned int)iAddress] = iAddress;
2b44051c
LOK
445 if (Primary == CecLogicalAddress::Unknown)
446 Primary = iAddress;
b7907707
LOK
447 }
448
a9fb46b4 449 property CecLogicalAddress Primary;
4ef3b314
LOK
450 property array<CecLogicalAddress> ^ Addresses;
451 };
452
453 public ref class CecDatapacket
454 {
455 public:
456 CecDatapacket(void)
457 {
458 Data = gcnew array<uint8_t>(100);
459 Size = 0;
460 }
461
462 void PushBack(uint8_t data)
463 {
464 if (Size < 100)
465 {
466 Data[Size] = data;
467 Size++;
468 }
469 }
470
471 property array<uint8_t> ^ Data;
472 property uint8_t Size;
473 };
474
475 public ref class CecCommand
476 {
477 public:
478 CecCommand(CecLogicalAddress iInitiator, CecLogicalAddress iDestination, bool bAck, bool bEom, CecOpcode iOpcode, int32_t iTransmitTimeout)
479 {
480 Initiator = iInitiator;
481 Destination = iDestination;
482 Ack = bAck;
483 Eom = bEom;
484 Opcode = iOpcode;
485 OpcodeSet = true;
486 TransmitTimeout = iTransmitTimeout;
487 Parameters = gcnew CecDatapacket;
488 Empty = false;
489 }
490
491 CecCommand(void)
492 {
493 Initiator = CecLogicalAddress::Unknown;
494 Destination = CecLogicalAddress::Unknown;
495 Ack = false;
496 Eom = false;
497 Opcode = CecOpcode::None;
498 OpcodeSet = false;
499 TransmitTimeout = 0;
500 Parameters = gcnew CecDatapacket;
501 Empty = true;
502 }
503
504 void PushBack(uint8_t data)
505 {
506 if (Initiator == CecLogicalAddress::Unknown && Destination == CecLogicalAddress::Unknown)
507 {
508 Initiator = (CecLogicalAddress) (data >> 4);
509 Destination = (CecLogicalAddress) (data & 0xF);
510 }
511 else if (!OpcodeSet)
512 {
513 OpcodeSet = true;
514 Opcode = (CecOpcode)data;
515 }
516 else
517 {
518 Parameters->PushBack(data);
519 }
520 }
521
522 property bool Empty;
523 property CecLogicalAddress Initiator;
524 property CecLogicalAddress Destination;
525 property bool Ack;
526 property bool Eom;
527 property CecOpcode Opcode;
528 property CecDatapacket ^ Parameters;
529 property bool OpcodeSet;
530 property int32_t TransmitTimeout;
531 };
532
533 public ref class CecKeypress
534 {
535 public:
04be3a97 536 CecKeypress(CecUserControlCode iKeycode, unsigned int iDuration)
4ef3b314
LOK
537 {
538 Keycode = iKeycode;
539 Duration = iDuration;
540 Empty = false;
541 }
542
543 CecKeypress(void)
544 {
04be3a97 545 Keycode = CecUserControlCode::Unknown;
4ef3b314
LOK
546 Duration = 0;
547 Empty = true;
548 }
549
04be3a97
LOK
550 property bool Empty;
551 property CecUserControlCode Keycode;
552 property unsigned int Duration;
4ef3b314
LOK
553 };
554
555 public ref class CecLogMessage
556 {
557 public:
558 CecLogMessage(System::String ^ strMessage, CecLogLevel iLevel, int64_t iTime)
559 {
560 Message = strMessage;
561 Level = iLevel;
562 Time = iTime;
563 Empty = false;
564 }
565
566 CecLogMessage(void)
567 {
568 Message = "";
569 Level = CecLogLevel::None;
570 Time = 0;
571 Empty = true;
572 }
573
574 property bool Empty;
575 property System::String ^Message;
576 property CecLogLevel Level;
577 property int64_t Time;
578 };
579
32403cc3
LOK
580 ref class CecCallbackMethods; //forward
581 public ref class LibCECConfiguration
582 {
583 public:
584 LibCECConfiguration(void)
585 {
586 DeviceName = "";
587 DeviceTypes = gcnew CecDeviceTypeList();
8670c970 588 AutodetectAddress = true;
32403cc3
LOK
589 PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
590 BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE;
591 HDMIPort = CEC_DEFAULT_HDMI_PORT;
592 ClientVersion = CecClientVersion::VersionPre1_5;
3efda01a 593 ServerVersion = CecServerVersion::VersionPre1_5;
b7907707 594 TvVendor = CecVendorId::Unknown;
32403cc3
LOK
595
596 GetSettingsFromROM = false;
597 UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1;
b7907707
LOK
598 ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1;
599
600 WakeDevices = gcnew CecLogicalAddresses();
601 if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1)
602 WakeDevices->Set(CecLogicalAddress::Tv);
603
604 PowerOffDevices = gcnew CecLogicalAddresses();
605 if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1)
606 PowerOffDevices->Set(CecLogicalAddress::Broadcast);
607
32403cc3
LOK
608 PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1;
609 PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1;
92da1117
MK
610
611 SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1;
612 LogicalAddresses = gcnew CecLogicalAddresses();
613 FirmwareVersion = 1;
614 PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1;
615 ShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1;
616 DeviceLanguage = "";
32403cc3
LOK
617 }
618
619 void SetCallbacks(CecCallbackMethods ^callbacks)
620 {
621 Callbacks = callbacks;
622 }
623
3efda01a
LOK
624 void Update(const CEC::libcec_configuration &config)
625 {
626 DeviceName = gcnew System::String(config.strDeviceName);
627
628 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
629 DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr];
630
631 AutodetectAddress = config.bAutodetectAddress == 1;
632 PhysicalAddress = config.iPhysicalAddress;
633 BaseDevice = (CecLogicalAddress)config.baseDevice;
634 HDMIPort = config.iHDMIPort;
635 ClientVersion = (CecClientVersion)config.clientVersion;
636 ServerVersion = (CecServerVersion)config.serverVersion;
637 TvVendor = (CecVendorId)config.tvVendor;
638
639 // player specific settings
640 GetSettingsFromROM = config.bGetSettingsFromROM == 1;
641 UseTVMenuLanguage = config.bUseTVMenuLanguage == 1;
642 ActivateSource = config.bActivateSource == 1;
643
644 WakeDevices->Clear();
645 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
646 if (config.wakeDevices[iPtr])
647 WakeDevices->Set((CecLogicalAddress)iPtr);
648
649 PowerOffDevices->Clear();
650 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
651 if (config.powerOffDevices[iPtr])
652 PowerOffDevices->Set((CecLogicalAddress)iPtr);
653
654 PowerOffScreensaver = config.bPowerOffScreensaver == 1;
655 PowerOffOnStandby = config.bPowerOffOnStandby == 1;
b98fc43d 656
92da1117
MK
657 if (ServerVersion >= CecServerVersion::Version1_5_1)
658 SendInactiveSource = config.bSendInactiveSource == 1;
659
660 if (ServerVersion >= CecServerVersion::Version1_5_3)
661 {
662 LogicalAddresses->Clear();
663 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
664 if (config.logicalAddresses[iPtr])
665 LogicalAddresses->Set((CecLogicalAddress)iPtr);
666 }
667
668 if (ServerVersion >= CecServerVersion::Version1_6_0)
669 {
670 FirmwareVersion = config.iFirmwareVersion;
671 PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1;
672 ShutdownOnStandby = config.bShutdownOnStandby == 1;
673 }
674
675 if (ServerVersion >= CecServerVersion::Version1_6_2)
676 DeviceLanguage = gcnew System::String(config.strDeviceLanguage);
d3b96c62
LOK
677
678 if (ServerVersion >= CecServerVersion::Version1_6_3)
679 MonitorOnlyClient = config.bMonitorOnly == 1;
3efda01a
LOK
680 }
681
b7907707
LOK
682 property System::String ^ DeviceName;
683 property CecDeviceTypeList ^ DeviceTypes;
8670c970 684 property bool AutodetectAddress;
b7907707
LOK
685 property uint16_t PhysicalAddress;
686 property CecLogicalAddress BaseDevice;
687 property uint8_t HDMIPort;
688 property CecClientVersion ClientVersion;
3efda01a 689 property CecServerVersion ServerVersion;
b7907707 690 property CecVendorId TvVendor;
32403cc3
LOK
691
692 // player specific settings
b7907707
LOK
693 property bool GetSettingsFromROM;
694 property bool UseTVMenuLanguage;
695 property bool ActivateSource;
696 property CecLogicalAddresses ^WakeDevices;
697 property CecLogicalAddresses ^PowerOffDevices;
698 property bool PowerOffScreensaver;
699 property bool PowerOffOnStandby;
92da1117
MK
700 property bool SendInactiveSource;
701 property CecLogicalAddresses ^LogicalAddresses;
702 property uint16_t FirmwareVersion;
703 property bool PowerOffDevicesOnStandby;
704 property bool ShutdownOnStandby;
d3b96c62 705 property bool MonitorOnlyClient;
92da1117 706 property System::String ^ DeviceLanguage;
b7907707 707 property CecCallbackMethods ^ Callbacks;
32403cc3
LOK
708 };
709
4ef3b314
LOK
710 // the callback methods are called by unmanaged code, so we need some delegates for this
711 #pragma unmanaged
712 // unmanaged callback methods
713 typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message);
714 typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key);
715 typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command);
32403cc3 716 typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config);
6e919697 717 typedef int (__stdcall *ALERTCB) (const CEC::libcec_alert, const CEC::libcec_parameter &data);
c3a20edb 718 typedef int (__stdcall *MENUCB) (const CEC::cec_menu_state newVal);
29d5198c 719 typedef void (__stdcall *ACTICB) (const CEC::cec_logical_address logicalAddress, const uint8_t bActivated);
4ef3b314 720
dc6366e8
LOK
721 typedef struct
722 {
723 LOGCB logCB;
724 KEYCB keyCB;
725 COMMANDCB commandCB;
726 CONFIGCB configCB;
727 ALERTCB alertCB;
728 MENUCB menuCB;
729 ACTICB sourceActivatedCB;
730 } UnmanagedCecCallbacks;
731
732 static PLATFORM::CMutex g_callbackMutex;
733 static std::vector<UnmanagedCecCallbacks> g_unmanagedCallbacks;
734 static CEC::ICECCallbacks g_cecCallbacks;
4ef3b314
LOK
735
736 int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message)
737 {
dc6366e8
LOK
738 if (cbParam)
739 {
740 size_t iPtr = (size_t)cbParam;
741 PLATFORM::CLockObject lock(g_callbackMutex);
742 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
743 return g_unmanagedCallbacks[iPtr].logCB(message);
744 }
4ef3b314
LOK
745 return 0;
746 }
747
748 int CecKeyPressCB(void *cbParam, const CEC::cec_keypress &key)
749 {
dc6366e8
LOK
750 if (cbParam)
751 {
752 size_t iPtr = (size_t)cbParam;
753 PLATFORM::CLockObject lock(g_callbackMutex);
754 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
755 return g_unmanagedCallbacks[iPtr].keyCB(key);
756 }
4ef3b314
LOK
757 return 0;
758 }
759
760 int CecCommandCB(void *cbParam, const CEC::cec_command &command)
761 {
dc6366e8
LOK
762 if (cbParam)
763 {
764 size_t iPtr = (size_t)cbParam;
765 PLATFORM::CLockObject lock(g_callbackMutex);
766 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
767 return g_unmanagedCallbacks[iPtr].commandCB(command);
768 }
4ef3b314
LOK
769 return 0;
770 }
771
32403cc3
LOK
772 int CecConfigCB(void *cbParam, const CEC::libcec_configuration &config)
773 {
dc6366e8
LOK
774 if (cbParam)
775 {
776 size_t iPtr = (size_t)cbParam;
777 PLATFORM::CLockObject lock(g_callbackMutex);
778 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
779 return g_unmanagedCallbacks[iPtr].configCB(config);
780 }
32403cc3
LOK
781 return 0;
782 }
783
6e919697 784 int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter &data)
5ee37222 785 {
dc6366e8
LOK
786 if (cbParam)
787 {
788 size_t iPtr = (size_t)cbParam;
789 PLATFORM::CLockObject lock(g_callbackMutex);
790 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
791 return g_unmanagedCallbacks[iPtr].alertCB(alert, data);
792 }
5ee37222
MK
793 return 0;
794 }
795
c3a20edb
LOK
796 int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal)
797 {
dc6366e8
LOK
798 if (cbParam)
799 {
800 size_t iPtr = (size_t)cbParam;
801 PLATFORM::CLockObject lock(g_callbackMutex);
802 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
803 return g_unmanagedCallbacks[iPtr].menuCB(newVal);
804 }
c3a20edb
LOK
805 return 0;
806 }
807
29d5198c
LOK
808 void CecSourceActivatedCB(void *cbParam, const CEC::cec_logical_address logicalAddress, const uint8_t bActivated)
809 {
dc6366e8
LOK
810 if (cbParam)
811 {
812 size_t iPtr = (size_t)cbParam;
813 PLATFORM::CLockObject lock(g_callbackMutex);
814 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
815 g_unmanagedCallbacks[iPtr].sourceActivatedCB(logicalAddress, bActivated);
816 }
29d5198c
LOK
817 }
818
4ef3b314
LOK
819 #pragma managed
820 // delegates for the unmanaged callback methods
dc6366e8
LOK
821 public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &);
822 public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &);
823 public delegate int CecCommandManagedDelegate(const CEC::cec_command &);
824 public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &);
825 public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &);
826 public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state newVal);
29d5198c 827 public delegate void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated);
4ef3b314 828
dc6366e8
LOK
829 void AssignCallbacks()
830 {
831 g_cecCallbacks.CBCecLogMessage = CecLogMessageCB;
832 g_cecCallbacks.CBCecKeyPress = CecKeyPressCB;
833 g_cecCallbacks.CBCecCommand = CecCommandCB;
834 g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB;
835 g_cecCallbacks.CBCecAlert = CecAlertCB;
836 g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB;
837 g_cecCallbacks.CBCecSourceActivated = CecSourceActivatedCB;
838 }
839
4ef3b314
LOK
840 // callback method interface
841 public ref class CecCallbackMethods
842 {
843 public:
11fea069
LOK
844 CecCallbackMethods(void)
845 {
dc6366e8
LOK
846 m_iCallbackPtr = -1;
847 AssignCallbacks();
11fea069
LOK
848 m_bHasCallbacks = false;
849 m_bDelegatesCreated = false;
850 }
4ef3b314 851
dc6366e8
LOK
852 ~CecCallbackMethods(void)
853 {
854 DestroyDelegates();
855 }
856
857 size_t GetCallbackPtr(void)
858 {
859 PLATFORM::CLockObject lock(g_callbackMutex);
860 return m_iCallbackPtr;
861 }
4ef3b314
LOK
862
863 protected:
864 !CecCallbackMethods(void)
865 {
866 DestroyDelegates();
867 }
868
869 public:
dae4328c
LOK
870 virtual void DisableCallbacks(void)
871 {
11fea069 872 DestroyDelegates();
dae4328c 873 }
11fea069 874
4ef3b314
LOK
875 virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks)
876 {
11fea069 877 CreateDelegates();
4ef3b314
LOK
878 if (!m_bHasCallbacks)
879 {
880 m_bHasCallbacks = true;
881 m_callbacks = callbacks;
882 return true;
883 }
884
885 return false;
886 }
887
888 virtual int ReceiveLogMessage(CecLogMessage ^ message)
889 {
890 return 0;
891 }
892
893 virtual int ReceiveKeypress(CecKeypress ^ key)
894 {
895 return 0;
896 }
897
898 virtual int ReceiveCommand(CecCommand ^ command)
899 {
900 return 0;
901 }
902
32403cc3
LOK
903 virtual int ConfigurationChanged(LibCECConfiguration ^ config)
904 {
905 return 0;
906 }
6e919697
MK
907
908 virtual int ReceiveAlert(CecAlert alert, CecParameter ^ data)
909 {
910 return 0;
911 }
912
c3a20edb
LOK
913 virtual int ReceiveMenuStateChange(CecMenuState newVal)
914 {
915 return 0;
916 }
917
29d5198c
LOK
918 virtual void SourceActivated(CecLogicalAddress logicalAddress, bool bActivated)
919 {
920 }
921
4ef3b314
LOK
922 protected:
923 // managed callback methods
924 int CecLogMessageManaged(const CEC::cec_log_message &message)
925 {
926 int iReturn(0);
927 if (m_bHasCallbacks)
928 iReturn = m_callbacks->ReceiveLogMessage(gcnew CecLogMessage(gcnew System::String(message.message), (CecLogLevel)message.level, message.time));
929 return iReturn;
930 }
931
932 int CecKeyPressManaged(const CEC::cec_keypress &key)
933 {
934 int iReturn(0);
935 if (m_bHasCallbacks)
04be3a97 936 iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration));
4ef3b314
LOK
937 return iReturn;
938 }
939
940 int CecCommandManaged(const CEC::cec_command &command)
941 {
942 int iReturn(0);
943 if (m_bHasCallbacks)
944 {
945 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);
946 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
947 newCommand->Parameters->PushBack(command.parameters[iPtr]);
948 iReturn = m_callbacks->ReceiveCommand(newCommand);
949 }
950 return iReturn;
951 }
952
32403cc3
LOK
953 int CecConfigManaged(const CEC::libcec_configuration &config)
954 {
955 int iReturn(0);
956 if (m_bHasCallbacks)
957 {
958 LibCECConfiguration ^netConfig = gcnew LibCECConfiguration();
3efda01a 959 netConfig->Update(config);
32403cc3
LOK
960 iReturn = m_callbacks->ConfigurationChanged(netConfig);
961 }
962 return iReturn;
963 }
964
6e919697
MK
965 int CecAlertManaged(const CEC::libcec_alert alert, const CEC::libcec_parameter &data)
966 {
967 int iReturn(0);
968 if (m_bHasCallbacks)
969 {
970 CecParameterType newType = (CecParameterType)data.paramType;
971 if (newType == CecParameterType::ParameterTypeString)
972 {
973 System::String ^ newData = gcnew System::String((const char *)data.paramData, 0, 128);
974 CecParameter ^ newParam = gcnew CecParameter(newType, newData);
975 iReturn = m_callbacks->ReceiveAlert((CecAlert)alert, newParam);
976 }
977 }
978 return iReturn;
979 }
980
c3a20edb
LOK
981 int CecMenuManaged(const CEC::cec_menu_state newVal)
982 {
983 int iReturn(0);
984 if (m_bHasCallbacks)
985 {
986 iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal);
987 }
988 return iReturn;
989 }
990
29d5198c
LOK
991 void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated)
992 {
993 if (m_bHasCallbacks)
994 m_callbacks->SourceActivated((CecLogicalAddress)logicalAddress, bActivated == 1);
995 }
996
4ef3b314
LOK
997 void DestroyDelegates()
998 {
11fea069
LOK
999 m_bHasCallbacks = false;
1000 if (m_bDelegatesCreated)
006b76b9 1001 {
11fea069 1002 m_bDelegatesCreated = false;
006b76b9
LOK
1003 m_logMessageGCHandle.Free();
1004 m_keypressGCHandle.Free();
1005 m_commandGCHandle.Free();
c3a20edb
LOK
1006 m_alertGCHandle.Free();
1007 m_menuGCHandle.Free();
29d5198c 1008 m_sourceActivatedGCHandle.Free();
006b76b9 1009 }
4ef3b314
LOK
1010 }
1011
11fea069
LOK
1012 void CreateDelegates()
1013 {
1014 DestroyDelegates();
1015
1016 if (!m_bDelegatesCreated)
1017 {
1018 msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context();
1019
1020 // create the delegate method for the log message callback
dc6366e8
LOK
1021 m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged);
1022 m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate);
1023 m_logMessageCallback = static_cast<LOGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer());
11fea069
LOK
1024
1025 // create the delegate method for the keypress callback
dc6366e8
LOK
1026 m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged);
1027 m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate);
1028 m_keypressCallback = static_cast<KEYCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer());
11fea069
LOK
1029
1030 // create the delegate method for the command callback
dc6366e8
LOK
1031 m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged);
1032 m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate);
1033 m_commandCallback = static_cast<COMMANDCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer());
11fea069
LOK
1034
1035 // create the delegate method for the configuration change callback
dc6366e8
LOK
1036 m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged);
1037 m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate);
1038 m_configCallback = static_cast<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer());
11fea069 1039
5ee37222 1040 // create the delegate method for the alert callback
dc6366e8
LOK
1041 m_alertDelegate = gcnew CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged);
1042 m_alertGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate);
1043 m_alertCallback = static_cast<ALERTCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer());
5ee37222 1044
c3a20edb 1045 // create the delegate method for the menu callback
dc6366e8
LOK
1046 m_menuDelegate = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged);
1047 m_menuGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate);
1048 m_menuCallback = static_cast<MENUCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer());
c3a20edb 1049
29d5198c 1050 // create the delegate method for the source activated callback
dc6366e8
LOK
1051 m_sourceActivatedDelegate = gcnew CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged);
1052 m_sourceActivatedGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate);
1053 m_sourceActivatedCallback = static_cast<ACTICB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate).ToPointer());
29d5198c 1054
11fea069 1055 delete context;
dc6366e8
LOK
1056
1057 UnmanagedCecCallbacks unmanagedCallbacks;
1058 unmanagedCallbacks.logCB = m_logMessageCallback;
1059 unmanagedCallbacks.keyCB = m_keypressCallback;
1060 unmanagedCallbacks.commandCB = m_commandCallback;
1061 unmanagedCallbacks.configCB = m_configCallback;
1062 unmanagedCallbacks.alertCB = m_alertCallback;
1063 unmanagedCallbacks.menuCB = m_menuCallback;
1064 unmanagedCallbacks.sourceActivatedCB = m_sourceActivatedCallback;
1065
1066 PLATFORM::CLockObject lock(g_callbackMutex);
1067 g_unmanagedCallbacks.push_back(unmanagedCallbacks);
1068 m_iCallbackPtr = g_unmanagedCallbacks.size() - 1;
1069 m_bDelegatesCreated = true;
11fea069
LOK
1070 }
1071 }
1072
4ef3b314
LOK
1073 CecLogMessageManagedDelegate ^ m_logMessageDelegate;
1074 static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle;
1075 LOGCB m_logMessageCallback;
1076
1077 CecKeyPressManagedDelegate ^ m_keypressDelegate;
1078 static System::Runtime::InteropServices::GCHandle m_keypressGCHandle;
1079 KEYCB m_keypressCallback;
1080
1081 CecCommandManagedDelegate ^ m_commandDelegate;
1082 static System::Runtime::InteropServices::GCHandle m_commandGCHandle;
1083 COMMANDCB m_commandCallback;
1084
32403cc3
LOK
1085 CecConfigManagedDelegate ^ m_configDelegate;
1086 static System::Runtime::InteropServices::GCHandle m_configGCHandle;
1087 CONFIGCB m_configCallback;
1088
5ee37222
MK
1089 CecAlertManagedDelegate ^ m_alertDelegate;
1090 static System::Runtime::InteropServices::GCHandle m_alertGCHandle;
dc6366e8 1091 ALERTCB m_alertCallback;
5ee37222 1092
c3a20edb
LOK
1093 CecMenuManagedDelegate ^ m_menuDelegate;
1094 static System::Runtime::InteropServices::GCHandle m_menuGCHandle;
1095 MENUCB m_menuCallback;
1096
29d5198c
LOK
1097 CecSourceActivatedManagedDelegate ^ m_sourceActivatedDelegate;
1098 static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle;
1099 ACTICB m_sourceActivatedCallback;
1100
4ef3b314
LOK
1101 CecCallbackMethods ^ m_callbacks;
1102 bool m_bHasCallbacks;
11fea069 1103 bool m_bDelegatesCreated;
dc6366e8 1104 size_t m_iCallbackPtr;
4ef3b314 1105 };
4ef3b314 1106}