removed deprecated methods and fields
[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 373 Version1_8_0 = 0x1800,
1664420d
LOK
374 Version1_8_1 = 0x1801,
375 Version1_8_2 = 0x1802,
376 Version1_9_0 = 0x1900
4ef3b314
LOK
377 };
378
e4a7396c 379 public enum class CecServerVersion
3efda01a
LOK
380 {
381 VersionPre1_5 = 0,
a8fffd1b 382 Version1_5_0 = 0x1500,
e4a7396c
LOK
383 Version1_5_1 = 0x1501,
384 Version1_5_2 = 0x1502,
385 Version1_5_3 = 0x1503,
386 Version1_6_0 = 0x1600,
6d0364f9 387 Version1_6_1 = 0x1601,
c2ce7bd1
LOK
388 Version1_6_2 = 0x1602,
389 Version1_6_3 = 0x1603,
390 Version1_7_0 = 0x1700,
2b44051c
LOK
391 Version1_7_1 = 0x1701,
392 Version1_7_2 = 0x1702,
7e316a2f 393 Version1_8_0 = 0x1800,
1664420d
LOK
394 Version1_8_1 = 0x1801,
395 Version1_8_2 = 0x1802,
396 Version1_9_0 = 0x1900
3efda01a
LOK
397 };
398
4ef3b314
LOK
399 public ref class CecAdapter
400 {
401 public:
402 CecAdapter(System::String ^ strPath, System::String ^ strComPort)
403 {
404 Path = strPath;
405 ComPort = strComPort;
406 }
407
408 property System::String ^ Path;
409 property System::String ^ ComPort;
410 };
411
412 public ref class CecDeviceTypeList
413 {
414 public:
415 CecDeviceTypeList(void)
416 {
417 Types = gcnew array<CecDeviceType>(5);
418 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
419 Types[iPtr] = CecDeviceType::Reserved;
420 }
421
422 property array<CecDeviceType> ^ Types;
423 };
424
425 public ref class CecLogicalAddresses
426 {
427 public:
428 CecLogicalAddresses(void)
429 {
430 Addresses = gcnew array<CecLogicalAddress>(16);
b7907707
LOK
431 Clear();
432 }
433
434 void Clear(void)
435 {
2b44051c 436 Primary = CecLogicalAddress::Unknown;
4ef3b314 437 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
63851508 438 Addresses[iPtr] = CecLogicalAddress::Unknown;
4ef3b314
LOK
439 }
440
441 bool IsSet(CecLogicalAddress iAddress)
442 {
63851508 443 return Addresses[(unsigned int)iAddress] != CecLogicalAddress::Unknown;
4ef3b314
LOK
444 }
445
b7907707
LOK
446 void Set(CecLogicalAddress iAddress)
447 {
448 Addresses[(unsigned int)iAddress] = iAddress;
2b44051c
LOK
449 if (Primary == CecLogicalAddress::Unknown)
450 Primary = iAddress;
b7907707
LOK
451 }
452
a9fb46b4 453 property CecLogicalAddress Primary;
4ef3b314
LOK
454 property array<CecLogicalAddress> ^ Addresses;
455 };
456
457 public ref class CecDatapacket
458 {
459 public:
460 CecDatapacket(void)
461 {
462 Data = gcnew array<uint8_t>(100);
463 Size = 0;
464 }
465
466 void PushBack(uint8_t data)
467 {
468 if (Size < 100)
469 {
470 Data[Size] = data;
471 Size++;
472 }
473 }
474
475 property array<uint8_t> ^ Data;
476 property uint8_t Size;
477 };
478
479 public ref class CecCommand
480 {
481 public:
482 CecCommand(CecLogicalAddress iInitiator, CecLogicalAddress iDestination, bool bAck, bool bEom, CecOpcode iOpcode, int32_t iTransmitTimeout)
483 {
484 Initiator = iInitiator;
485 Destination = iDestination;
486 Ack = bAck;
487 Eom = bEom;
488 Opcode = iOpcode;
489 OpcodeSet = true;
490 TransmitTimeout = iTransmitTimeout;
491 Parameters = gcnew CecDatapacket;
492 Empty = false;
493 }
494
495 CecCommand(void)
496 {
497 Initiator = CecLogicalAddress::Unknown;
498 Destination = CecLogicalAddress::Unknown;
499 Ack = false;
500 Eom = false;
501 Opcode = CecOpcode::None;
502 OpcodeSet = false;
503 TransmitTimeout = 0;
504 Parameters = gcnew CecDatapacket;
505 Empty = true;
506 }
507
508 void PushBack(uint8_t data)
509 {
510 if (Initiator == CecLogicalAddress::Unknown && Destination == CecLogicalAddress::Unknown)
511 {
512 Initiator = (CecLogicalAddress) (data >> 4);
513 Destination = (CecLogicalAddress) (data & 0xF);
514 }
515 else if (!OpcodeSet)
516 {
517 OpcodeSet = true;
518 Opcode = (CecOpcode)data;
519 }
520 else
521 {
522 Parameters->PushBack(data);
523 }
524 }
525
526 property bool Empty;
527 property CecLogicalAddress Initiator;
528 property CecLogicalAddress Destination;
529 property bool Ack;
530 property bool Eom;
531 property CecOpcode Opcode;
532 property CecDatapacket ^ Parameters;
533 property bool OpcodeSet;
534 property int32_t TransmitTimeout;
535 };
536
537 public ref class CecKeypress
538 {
539 public:
04be3a97 540 CecKeypress(CecUserControlCode iKeycode, unsigned int iDuration)
4ef3b314
LOK
541 {
542 Keycode = iKeycode;
543 Duration = iDuration;
544 Empty = false;
545 }
546
547 CecKeypress(void)
548 {
04be3a97 549 Keycode = CecUserControlCode::Unknown;
4ef3b314
LOK
550 Duration = 0;
551 Empty = true;
552 }
553
04be3a97
LOK
554 property bool Empty;
555 property CecUserControlCode Keycode;
556 property unsigned int Duration;
4ef3b314
LOK
557 };
558
559 public ref class CecLogMessage
560 {
561 public:
562 CecLogMessage(System::String ^ strMessage, CecLogLevel iLevel, int64_t iTime)
563 {
564 Message = strMessage;
565 Level = iLevel;
566 Time = iTime;
567 Empty = false;
568 }
569
570 CecLogMessage(void)
571 {
572 Message = "";
573 Level = CecLogLevel::None;
574 Time = 0;
575 Empty = true;
576 }
577
578 property bool Empty;
579 property System::String ^Message;
580 property CecLogLevel Level;
581 property int64_t Time;
582 };
583
32403cc3
LOK
584 ref class CecCallbackMethods; //forward
585 public ref class LibCECConfiguration
586 {
587 public:
588 LibCECConfiguration(void)
589 {
590 DeviceName = "";
591 DeviceTypes = gcnew CecDeviceTypeList();
8670c970 592 AutodetectAddress = true;
32403cc3
LOK
593 PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
594 BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE;
595 HDMIPort = CEC_DEFAULT_HDMI_PORT;
596 ClientVersion = CecClientVersion::VersionPre1_5;
3efda01a 597 ServerVersion = CecServerVersion::VersionPre1_5;
b7907707 598 TvVendor = CecVendorId::Unknown;
32403cc3
LOK
599
600 GetSettingsFromROM = false;
601 UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1;
b7907707
LOK
602 ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1;
603
604 WakeDevices = gcnew CecLogicalAddresses();
605 if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1)
606 WakeDevices->Set(CecLogicalAddress::Tv);
607
608 PowerOffDevices = gcnew CecLogicalAddresses();
609 if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1)
610 PowerOffDevices->Set(CecLogicalAddress::Broadcast);
611
32403cc3
LOK
612 PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1;
613 PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1;
92da1117
MK
614
615 SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1;
616 LogicalAddresses = gcnew CecLogicalAddresses();
617 FirmwareVersion = 1;
618 PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1;
619 ShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1;
620 DeviceLanguage = "";
32403cc3
LOK
621 }
622
623 void SetCallbacks(CecCallbackMethods ^callbacks)
624 {
625 Callbacks = callbacks;
626 }
627
3efda01a
LOK
628 void Update(const CEC::libcec_configuration &config)
629 {
630 DeviceName = gcnew System::String(config.strDeviceName);
631
632 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
633 DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr];
634
635 AutodetectAddress = config.bAutodetectAddress == 1;
636 PhysicalAddress = config.iPhysicalAddress;
637 BaseDevice = (CecLogicalAddress)config.baseDevice;
638 HDMIPort = config.iHDMIPort;
639 ClientVersion = (CecClientVersion)config.clientVersion;
640 ServerVersion = (CecServerVersion)config.serverVersion;
641 TvVendor = (CecVendorId)config.tvVendor;
642
643 // player specific settings
644 GetSettingsFromROM = config.bGetSettingsFromROM == 1;
645 UseTVMenuLanguage = config.bUseTVMenuLanguage == 1;
646 ActivateSource = config.bActivateSource == 1;
647
648 WakeDevices->Clear();
649 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
650 if (config.wakeDevices[iPtr])
651 WakeDevices->Set((CecLogicalAddress)iPtr);
652
653 PowerOffDevices->Clear();
654 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
655 if (config.powerOffDevices[iPtr])
656 PowerOffDevices->Set((CecLogicalAddress)iPtr);
657
658 PowerOffScreensaver = config.bPowerOffScreensaver == 1;
659 PowerOffOnStandby = config.bPowerOffOnStandby == 1;
b98fc43d 660
92da1117
MK
661 if (ServerVersion >= CecServerVersion::Version1_5_1)
662 SendInactiveSource = config.bSendInactiveSource == 1;
663
664 if (ServerVersion >= CecServerVersion::Version1_5_3)
665 {
666 LogicalAddresses->Clear();
667 for (uint8_t iPtr = 0; iPtr <= 16; iPtr++)
668 if (config.logicalAddresses[iPtr])
669 LogicalAddresses->Set((CecLogicalAddress)iPtr);
670 }
671
672 if (ServerVersion >= CecServerVersion::Version1_6_0)
673 {
674 FirmwareVersion = config.iFirmwareVersion;
675 PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1;
676 ShutdownOnStandby = config.bShutdownOnStandby == 1;
677 }
678
679 if (ServerVersion >= CecServerVersion::Version1_6_2)
680 DeviceLanguage = gcnew System::String(config.strDeviceLanguage);
d3b96c62
LOK
681
682 if (ServerVersion >= CecServerVersion::Version1_6_3)
683 MonitorOnlyClient = config.bMonitorOnly == 1;
3efda01a
LOK
684 }
685
b7907707
LOK
686 property System::String ^ DeviceName;
687 property CecDeviceTypeList ^ DeviceTypes;
8670c970 688 property bool AutodetectAddress;
b7907707
LOK
689 property uint16_t PhysicalAddress;
690 property CecLogicalAddress BaseDevice;
691 property uint8_t HDMIPort;
692 property CecClientVersion ClientVersion;
3efda01a 693 property CecServerVersion ServerVersion;
b7907707 694 property CecVendorId TvVendor;
32403cc3
LOK
695
696 // player specific settings
b7907707
LOK
697 property bool GetSettingsFromROM;
698 property bool UseTVMenuLanguage;
699 property bool ActivateSource;
700 property CecLogicalAddresses ^WakeDevices;
701 property CecLogicalAddresses ^PowerOffDevices;
702 property bool PowerOffScreensaver;
703 property bool PowerOffOnStandby;
92da1117
MK
704 property bool SendInactiveSource;
705 property CecLogicalAddresses ^LogicalAddresses;
706 property uint16_t FirmwareVersion;
707 property bool PowerOffDevicesOnStandby;
708 property bool ShutdownOnStandby;
d3b96c62 709 property bool MonitorOnlyClient;
92da1117 710 property System::String ^ DeviceLanguage;
b7907707 711 property CecCallbackMethods ^ Callbacks;
32403cc3
LOK
712 };
713
4ef3b314
LOK
714 // the callback methods are called by unmanaged code, so we need some delegates for this
715 #pragma unmanaged
716 // unmanaged callback methods
717 typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message);
718 typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key);
719 typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command);
32403cc3 720 typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config);
6e919697 721 typedef int (__stdcall *ALERTCB) (const CEC::libcec_alert, const CEC::libcec_parameter &data);
c3a20edb 722 typedef int (__stdcall *MENUCB) (const CEC::cec_menu_state newVal);
29d5198c 723 typedef void (__stdcall *ACTICB) (const CEC::cec_logical_address logicalAddress, const uint8_t bActivated);
4ef3b314 724
dc6366e8
LOK
725 typedef struct
726 {
727 LOGCB logCB;
728 KEYCB keyCB;
729 COMMANDCB commandCB;
730 CONFIGCB configCB;
731 ALERTCB alertCB;
732 MENUCB menuCB;
733 ACTICB sourceActivatedCB;
734 } UnmanagedCecCallbacks;
735
736 static PLATFORM::CMutex g_callbackMutex;
737 static std::vector<UnmanagedCecCallbacks> g_unmanagedCallbacks;
738 static CEC::ICECCallbacks g_cecCallbacks;
4ef3b314
LOK
739
740 int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message)
741 {
dc6366e8
LOK
742 if (cbParam)
743 {
744 size_t iPtr = (size_t)cbParam;
745 PLATFORM::CLockObject lock(g_callbackMutex);
746 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
747 return g_unmanagedCallbacks[iPtr].logCB(message);
748 }
4ef3b314
LOK
749 return 0;
750 }
751
752 int CecKeyPressCB(void *cbParam, const CEC::cec_keypress &key)
753 {
dc6366e8
LOK
754 if (cbParam)
755 {
756 size_t iPtr = (size_t)cbParam;
757 PLATFORM::CLockObject lock(g_callbackMutex);
758 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
759 return g_unmanagedCallbacks[iPtr].keyCB(key);
760 }
4ef3b314
LOK
761 return 0;
762 }
763
764 int CecCommandCB(void *cbParam, const CEC::cec_command &command)
765 {
dc6366e8
LOK
766 if (cbParam)
767 {
768 size_t iPtr = (size_t)cbParam;
769 PLATFORM::CLockObject lock(g_callbackMutex);
770 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
771 return g_unmanagedCallbacks[iPtr].commandCB(command);
772 }
4ef3b314
LOK
773 return 0;
774 }
775
32403cc3
LOK
776 int CecConfigCB(void *cbParam, const CEC::libcec_configuration &config)
777 {
dc6366e8
LOK
778 if (cbParam)
779 {
780 size_t iPtr = (size_t)cbParam;
781 PLATFORM::CLockObject lock(g_callbackMutex);
782 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
783 return g_unmanagedCallbacks[iPtr].configCB(config);
784 }
32403cc3
LOK
785 return 0;
786 }
787
6e919697 788 int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter &data)
5ee37222 789 {
dc6366e8
LOK
790 if (cbParam)
791 {
792 size_t iPtr = (size_t)cbParam;
793 PLATFORM::CLockObject lock(g_callbackMutex);
794 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
795 return g_unmanagedCallbacks[iPtr].alertCB(alert, data);
796 }
5ee37222
MK
797 return 0;
798 }
799
c3a20edb
LOK
800 int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal)
801 {
dc6366e8
LOK
802 if (cbParam)
803 {
804 size_t iPtr = (size_t)cbParam;
805 PLATFORM::CLockObject lock(g_callbackMutex);
806 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
807 return g_unmanagedCallbacks[iPtr].menuCB(newVal);
808 }
c3a20edb
LOK
809 return 0;
810 }
811
29d5198c
LOK
812 void CecSourceActivatedCB(void *cbParam, const CEC::cec_logical_address logicalAddress, const uint8_t bActivated)
813 {
dc6366e8
LOK
814 if (cbParam)
815 {
816 size_t iPtr = (size_t)cbParam;
817 PLATFORM::CLockObject lock(g_callbackMutex);
818 if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size())
819 g_unmanagedCallbacks[iPtr].sourceActivatedCB(logicalAddress, bActivated);
820 }
29d5198c
LOK
821 }
822
4ef3b314
LOK
823 #pragma managed
824 // delegates for the unmanaged callback methods
dc6366e8
LOK
825 public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &);
826 public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &);
827 public delegate int CecCommandManagedDelegate(const CEC::cec_command &);
828 public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &);
829 public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &);
830 public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state newVal);
29d5198c 831 public delegate void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated);
4ef3b314 832
dc6366e8
LOK
833 void AssignCallbacks()
834 {
835 g_cecCallbacks.CBCecLogMessage = CecLogMessageCB;
836 g_cecCallbacks.CBCecKeyPress = CecKeyPressCB;
837 g_cecCallbacks.CBCecCommand = CecCommandCB;
838 g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB;
839 g_cecCallbacks.CBCecAlert = CecAlertCB;
840 g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB;
841 g_cecCallbacks.CBCecSourceActivated = CecSourceActivatedCB;
842 }
843
4ef3b314
LOK
844 // callback method interface
845 public ref class CecCallbackMethods
846 {
847 public:
11fea069
LOK
848 CecCallbackMethods(void)
849 {
dc6366e8
LOK
850 m_iCallbackPtr = -1;
851 AssignCallbacks();
11fea069
LOK
852 m_bHasCallbacks = false;
853 m_bDelegatesCreated = false;
854 }
4ef3b314 855
dc6366e8
LOK
856 ~CecCallbackMethods(void)
857 {
858 DestroyDelegates();
859 }
860
861 size_t GetCallbackPtr(void)
862 {
863 PLATFORM::CLockObject lock(g_callbackMutex);
864 return m_iCallbackPtr;
865 }
4ef3b314
LOK
866
867 protected:
868 !CecCallbackMethods(void)
869 {
870 DestroyDelegates();
871 }
872
873 public:
dae4328c
LOK
874 virtual void DisableCallbacks(void)
875 {
11fea069 876 DestroyDelegates();
dae4328c 877 }
11fea069 878
4ef3b314
LOK
879 virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks)
880 {
11fea069 881 CreateDelegates();
4ef3b314
LOK
882 if (!m_bHasCallbacks)
883 {
884 m_bHasCallbacks = true;
885 m_callbacks = callbacks;
886 return true;
887 }
888
889 return false;
890 }
891
892 virtual int ReceiveLogMessage(CecLogMessage ^ message)
893 {
894 return 0;
895 }
896
897 virtual int ReceiveKeypress(CecKeypress ^ key)
898 {
899 return 0;
900 }
901
902 virtual int ReceiveCommand(CecCommand ^ command)
903 {
904 return 0;
905 }
906
32403cc3
LOK
907 virtual int ConfigurationChanged(LibCECConfiguration ^ config)
908 {
909 return 0;
910 }
6e919697
MK
911
912 virtual int ReceiveAlert(CecAlert alert, CecParameter ^ data)
913 {
914 return 0;
915 }
916
c3a20edb
LOK
917 virtual int ReceiveMenuStateChange(CecMenuState newVal)
918 {
919 return 0;
920 }
921
29d5198c
LOK
922 virtual void SourceActivated(CecLogicalAddress logicalAddress, bool bActivated)
923 {
924 }
925
4ef3b314
LOK
926 protected:
927 // managed callback methods
928 int CecLogMessageManaged(const CEC::cec_log_message &message)
929 {
930 int iReturn(0);
931 if (m_bHasCallbacks)
932 iReturn = m_callbacks->ReceiveLogMessage(gcnew CecLogMessage(gcnew System::String(message.message), (CecLogLevel)message.level, message.time));
933 return iReturn;
934 }
935
936 int CecKeyPressManaged(const CEC::cec_keypress &key)
937 {
938 int iReturn(0);
939 if (m_bHasCallbacks)
04be3a97 940 iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration));
4ef3b314
LOK
941 return iReturn;
942 }
943
944 int CecCommandManaged(const CEC::cec_command &command)
945 {
946 int iReturn(0);
947 if (m_bHasCallbacks)
948 {
949 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);
950 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
951 newCommand->Parameters->PushBack(command.parameters[iPtr]);
952 iReturn = m_callbacks->ReceiveCommand(newCommand);
953 }
954 return iReturn;
955 }
956
32403cc3
LOK
957 int CecConfigManaged(const CEC::libcec_configuration &config)
958 {
959 int iReturn(0);
960 if (m_bHasCallbacks)
961 {
962 LibCECConfiguration ^netConfig = gcnew LibCECConfiguration();
3efda01a 963 netConfig->Update(config);
32403cc3
LOK
964 iReturn = m_callbacks->ConfigurationChanged(netConfig);
965 }
966 return iReturn;
967 }
968
6e919697
MK
969 int CecAlertManaged(const CEC::libcec_alert alert, const CEC::libcec_parameter &data)
970 {
971 int iReturn(0);
972 if (m_bHasCallbacks)
973 {
974 CecParameterType newType = (CecParameterType)data.paramType;
975 if (newType == CecParameterType::ParameterTypeString)
976 {
977 System::String ^ newData = gcnew System::String((const char *)data.paramData, 0, 128);
978 CecParameter ^ newParam = gcnew CecParameter(newType, newData);
979 iReturn = m_callbacks->ReceiveAlert((CecAlert)alert, newParam);
980 }
981 }
982 return iReturn;
983 }
984
c3a20edb
LOK
985 int CecMenuManaged(const CEC::cec_menu_state newVal)
986 {
987 int iReturn(0);
988 if (m_bHasCallbacks)
989 {
990 iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal);
991 }
992 return iReturn;
993 }
994
29d5198c
LOK
995 void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated)
996 {
997 if (m_bHasCallbacks)
998 m_callbacks->SourceActivated((CecLogicalAddress)logicalAddress, bActivated == 1);
999 }
1000
4ef3b314
LOK
1001 void DestroyDelegates()
1002 {
11fea069
LOK
1003 m_bHasCallbacks = false;
1004 if (m_bDelegatesCreated)
006b76b9 1005 {
11fea069 1006 m_bDelegatesCreated = false;
006b76b9
LOK
1007 m_logMessageGCHandle.Free();
1008 m_keypressGCHandle.Free();
1009 m_commandGCHandle.Free();
c3a20edb
LOK
1010 m_alertGCHandle.Free();
1011 m_menuGCHandle.Free();
29d5198c 1012 m_sourceActivatedGCHandle.Free();
006b76b9 1013 }
4ef3b314
LOK
1014 }
1015
11fea069
LOK
1016 void CreateDelegates()
1017 {
1018 DestroyDelegates();
1019
1020 if (!m_bDelegatesCreated)
1021 {
1022 msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context();
1023
1024 // create the delegate method for the log message callback
dc6366e8
LOK
1025 m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged);
1026 m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate);
1027 m_logMessageCallback = static_cast<LOGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer());
11fea069
LOK
1028
1029 // create the delegate method for the keypress callback
dc6366e8
LOK
1030 m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged);
1031 m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate);
1032 m_keypressCallback = static_cast<KEYCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer());
11fea069
LOK
1033
1034 // create the delegate method for the command callback
dc6366e8
LOK
1035 m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged);
1036 m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate);
1037 m_commandCallback = static_cast<COMMANDCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer());
11fea069
LOK
1038
1039 // create the delegate method for the configuration change callback
dc6366e8
LOK
1040 m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged);
1041 m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate);
1042 m_configCallback = static_cast<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer());
11fea069 1043
5ee37222 1044 // create the delegate method for the alert callback
dc6366e8
LOK
1045 m_alertDelegate = gcnew CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged);
1046 m_alertGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate);
1047 m_alertCallback = static_cast<ALERTCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer());
5ee37222 1048
c3a20edb 1049 // create the delegate method for the menu callback
dc6366e8
LOK
1050 m_menuDelegate = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged);
1051 m_menuGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate);
1052 m_menuCallback = static_cast<MENUCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer());
c3a20edb 1053
29d5198c 1054 // create the delegate method for the source activated callback
dc6366e8
LOK
1055 m_sourceActivatedDelegate = gcnew CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged);
1056 m_sourceActivatedGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate);
1057 m_sourceActivatedCallback = static_cast<ACTICB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate).ToPointer());
29d5198c 1058
11fea069 1059 delete context;
dc6366e8
LOK
1060
1061 UnmanagedCecCallbacks unmanagedCallbacks;
1062 unmanagedCallbacks.logCB = m_logMessageCallback;
1063 unmanagedCallbacks.keyCB = m_keypressCallback;
1064 unmanagedCallbacks.commandCB = m_commandCallback;
1065 unmanagedCallbacks.configCB = m_configCallback;
1066 unmanagedCallbacks.alertCB = m_alertCallback;
1067 unmanagedCallbacks.menuCB = m_menuCallback;
1068 unmanagedCallbacks.sourceActivatedCB = m_sourceActivatedCallback;
1069
1070 PLATFORM::CLockObject lock(g_callbackMutex);
1071 g_unmanagedCallbacks.push_back(unmanagedCallbacks);
1072 m_iCallbackPtr = g_unmanagedCallbacks.size() - 1;
1073 m_bDelegatesCreated = true;
11fea069
LOK
1074 }
1075 }
1076
4ef3b314
LOK
1077 CecLogMessageManagedDelegate ^ m_logMessageDelegate;
1078 static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle;
1079 LOGCB m_logMessageCallback;
1080
1081 CecKeyPressManagedDelegate ^ m_keypressDelegate;
1082 static System::Runtime::InteropServices::GCHandle m_keypressGCHandle;
1083 KEYCB m_keypressCallback;
1084
1085 CecCommandManagedDelegate ^ m_commandDelegate;
1086 static System::Runtime::InteropServices::GCHandle m_commandGCHandle;
1087 COMMANDCB m_commandCallback;
1088
32403cc3
LOK
1089 CecConfigManagedDelegate ^ m_configDelegate;
1090 static System::Runtime::InteropServices::GCHandle m_configGCHandle;
1091 CONFIGCB m_configCallback;
1092
5ee37222
MK
1093 CecAlertManagedDelegate ^ m_alertDelegate;
1094 static System::Runtime::InteropServices::GCHandle m_alertGCHandle;
dc6366e8 1095 ALERTCB m_alertCallback;
5ee37222 1096
c3a20edb
LOK
1097 CecMenuManagedDelegate ^ m_menuDelegate;
1098 static System::Runtime::InteropServices::GCHandle m_menuGCHandle;
1099 MENUCB m_menuCallback;
1100
29d5198c
LOK
1101 CecSourceActivatedManagedDelegate ^ m_sourceActivatedDelegate;
1102 static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle;
1103 ACTICB m_sourceActivatedCallback;
1104
4ef3b314
LOK
1105 CecCallbackMethods ^ m_callbacks;
1106 bool m_bHasCallbacks;
11fea069 1107 bool m_bDelegatesCreated;
dc6366e8 1108 size_t m_iCallbackPtr;
4ef3b314 1109 };
4ef3b314 1110}