Commit | Line | Data |
---|---|---|
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 | ||
34 | #include <windows.h> | |
35 | #include <vcclr.h> | |
36 | #include <msclr/marshal.h> | |
37 | #include "../../include/cec.h" | |
38 | ||
39 | #using <System.dll> | |
40 | ||
41 | namespace CecSharp | |
42 | { | |
43 | public enum class CecDeviceType | |
44 | { | |
45 | Tv = 0, | |
46 | RecordingDevice = 1, | |
47 | Reserved = 2, | |
48 | Tuner = 3, | |
49 | PlaybackDevice = 4, | |
50 | AudioSystem = 5 | |
51 | }; | |
52 | ||
53 | public enum class CecLogLevel | |
54 | { | |
55 | None = 0, | |
56 | Error = 1, | |
57 | Warning = 2, | |
58 | Notice = 4, | |
59 | Traffic = 8, | |
60 | Debug = 16, | |
61 | All = 31 | |
62 | }; | |
63 | ||
64 | public enum class CecLogicalAddress | |
65 | { | |
66 | Unknown = -1, //not a valid logical address | |
67 | Tv = 0, | |
68 | RecordingDevice1 = 1, | |
69 | RecordingDevice2 = 2, | |
70 | Tuner1 = 3, | |
71 | PlaybackDevice1 = 4, | |
72 | AudioSystem = 5, | |
73 | Tuner2 = 6, | |
74 | Tuner3 = 7, | |
75 | PlaybackDevice2 = 8, | |
76 | RecordingDevice3 = 9, | |
77 | Tuner4 = 10, | |
78 | PlaybackDevice3 = 11, | |
79 | Reserved1 = 12, | |
80 | Reserved2 = 13, | |
81 | FreeUse = 14, | |
82 | Unregistered = 15, | |
83 | Broadcast = 15 | |
84 | }; | |
85 | ||
86 | public enum class CecPowerStatus | |
87 | { | |
88 | On = 0x00, | |
89 | Standby = 0x01, | |
90 | InTransitionStandbyToOn = 0x02, | |
91 | InTransitionOnToStandby = 0x03, | |
92 | Unknown = 0x99 | |
93 | }; | |
94 | ||
95 | public enum class CecVersion | |
96 | { | |
97 | Unknown = 0x00, | |
98 | V1_2 = 0x01, | |
99 | V1_2A = 0x02, | |
100 | V1_3 = 0x03, | |
101 | V1_3A = 0x04, | |
102 | V1_4 = 0x05 | |
103 | }; | |
104 | ||
105 | public enum class CecDisplayControl | |
106 | { | |
107 | DisplayForDefaultTime = 0x00, | |
108 | DisplayUntilCleared = 0x40, | |
109 | ClearPreviousMessage = 0x80, | |
110 | ReservedForFutureUse = 0xC0 | |
111 | }; | |
112 | ||
113 | public enum class CecMenuState | |
114 | { | |
115 | Activated = 0, | |
116 | Deactivated = 1 | |
117 | }; | |
118 | ||
119 | public enum class CecDeckControlMode | |
120 | { | |
121 | SkipForwardWind = 1, | |
122 | SkipReverseRewind = 2, | |
123 | Stop = 3, | |
124 | Eject = 4 | |
125 | }; | |
126 | ||
127 | public enum class CecDeckInfo | |
128 | { | |
129 | Play = 0x11, | |
130 | Record = 0x12, | |
131 | Reverse = 0x13, | |
132 | Still = 0x14, | |
133 | Slow = 0x15, | |
134 | SlowReverse = 0x16, | |
135 | FastForward = 0x17, | |
136 | FastReverse = 0x18, | |
137 | NoMedia = 0x19, | |
138 | Stop = 0x1A, | |
139 | SkipForwardWind = 0x1B, | |
140 | SkipReverseRewind = 0x1C, | |
141 | IndexSearchForward = 0x1D, | |
142 | IndexSearchReverse = 0x1E, | |
143 | OtherStatus = 0x1F | |
144 | }; | |
145 | ||
146 | public enum class CecUserControlCode | |
147 | { | |
148 | Select = 0x00, | |
149 | Up = 0x01, | |
150 | Down = 0x02, | |
151 | Left = 0x03, | |
152 | Right = 0x04, | |
153 | RightUp = 0x05, | |
154 | RightDown = 0x06, | |
155 | LeftUp = 0x07, | |
156 | LeftDown = 0x08, | |
157 | RootMenu = 0x09, | |
158 | SetupMenu = 0x0A, | |
159 | ContentsMenu = 0x0B, | |
160 | FavoriteMenu = 0x0C, | |
161 | Exit = 0x0D, | |
162 | Number0 = 0x20, | |
163 | Number1 = 0x21, | |
164 | Number2 = 0x22, | |
165 | Number3 = 0x23, | |
166 | Number4 = 0x24, | |
167 | Number5 = 0x25, | |
168 | Number6 = 0x26, | |
169 | Number7 = 0x27, | |
170 | Number8 = 0x28, | |
171 | Number9 = 0x29, | |
172 | Dot = 0x2A, | |
173 | Enter = 0x2B, | |
174 | Clear = 0x2C, | |
175 | NextFavorite = 0x2F, | |
176 | ChannelUp = 0x30, | |
177 | ChannelDown = 0x31, | |
178 | PreviousChannel = 0x32, | |
179 | SoundSelect = 0x33, | |
180 | InputSelect = 0x34, | |
181 | DisplayInformation = 0x35, | |
182 | Help = 0x36, | |
183 | PageUp = 0x37, | |
184 | PageDown = 0x38, | |
185 | Power = 0x40, | |
186 | VolumeUp = 0x41, | |
187 | VolumeDown = 0x42, | |
188 | Mute = 0x43, | |
189 | Play = 0x44, | |
190 | Stop = 0x45, | |
191 | Pause = 0x46, | |
192 | Record = 0x47, | |
193 | Rewind = 0x48, | |
194 | FastForward = 0x49, | |
195 | Eject = 0x4A, | |
196 | Forward = 0x4B, | |
197 | Backward = 0x4C, | |
198 | StopRecord = 0x4D, | |
199 | PauseRecord = 0x4E, | |
200 | Angle = 0x50, | |
201 | SubPicture = 0x51, | |
202 | VideoOnDemand = 0x52, | |
203 | ElectronicProgramGuide = 0x53, | |
204 | TimerProgramming = 0x54, | |
205 | InitialConfiguration = 0x55, | |
206 | PlayFunction = 0x60, | |
207 | PausePlayFunction = 0x61, | |
208 | RecordFunction = 0x62, | |
209 | PauseRecordFunction = 0x63, | |
210 | StopFunction = 0x64, | |
211 | MuteFunction = 0x65, | |
212 | RestoreVolumeFunction = 0x66, | |
213 | TuneFunction = 0x67, | |
214 | SelectMediaFunction = 0x68, | |
215 | SelectAVInputFunction = 0x69, | |
216 | SelectAudioInputFunction = 0x6A, | |
217 | PowerToggleFunction = 0x6B, | |
218 | PowerOffFunction = 0x6C, | |
219 | PowerOnFunction = 0x6D, | |
220 | F1Blue = 0x71, | |
221 | F2Red = 0X72, | |
222 | F3Green = 0x73, | |
223 | F4Yellow = 0x74, | |
224 | F5 = 0x75, | |
225 | Data = 0x76, | |
226 | Max = 0x76, | |
227 | Unknown | |
228 | }; | |
229 | ||
230 | public enum class CecVendorId | |
231 | { | |
232 | Samsung = 0x00F0, | |
233 | LG = 0xE091, | |
234 | Panasonic = 0x8045, | |
235 | Pioneer = 0xE036, | |
236 | Onkyo = 0x09B0, | |
237 | Yamaha = 0xA0DE, | |
238 | Philips = 0x903E, | |
de90f347 | 239 | Sony = 0x080046, |
4ef3b314 LOK |
240 | Unknown = 0 |
241 | }; | |
242 | ||
243 | public enum class CecAudioStatus | |
244 | { | |
245 | MuteStatusMask = 0x80, | |
246 | VolumeStatusMask = 0x7F, | |
247 | VolumeMin = 0x00, | |
248 | VolumeMax = 0x64, | |
249 | VolumeStatusUnknown = 0x7F | |
250 | }; | |
251 | ||
252 | public enum class CecOpcode | |
253 | { | |
254 | ActiveSource = 0x82, | |
255 | ImageViewOn = 0x04, | |
256 | TextViewOn = 0x0D, | |
257 | InactiveSource = 0x9D, | |
258 | RequestActiveSource = 0x85, | |
259 | RoutingChange = 0x80, | |
260 | RoutingInformation = 0x81, | |
261 | SetStreamPath = 0x86, | |
262 | Standby = 0x36, | |
263 | RecordOff = 0x0B, | |
264 | RecordOn = 0x09, | |
265 | RecordStatus = 0x0A, | |
266 | RecordTvScreen = 0x0F, | |
267 | ClearAnalogueTimer = 0x33, | |
268 | ClearDigitalTimer = 0x99, | |
269 | ClearExternalTimer = 0xA1, | |
270 | SetAnalogueTimer = 0x34, | |
271 | SetDigitalTimer = 0x97, | |
272 | SetExternalTimer = 0xA2, | |
273 | SetTimerProgramTitle = 0x67, | |
274 | TimerClearedStatus = 0x43, | |
275 | TimerStatus = 0x35, | |
276 | CecVersion = 0x9E, | |
277 | GetCecVersion = 0x9F, | |
278 | GivePhysicalAddress = 0x83, | |
279 | GetMenuLanguage = 0x91, | |
280 | ReportPhysicalAddress = 0x84, | |
281 | SetMenuLanguage = 0x32, | |
282 | DeckControl = 0x42, | |
283 | DeckStatus = 0x1B, | |
284 | GiveDeckStatus = 0x1A, | |
285 | Play = 0x41, | |
286 | GiveTunerDeviceStatus = 0x08, | |
287 | SelectAnalogueService = 0x92, | |
288 | SelectDigtalService = 0x93, | |
289 | TunerDeviceStatus = 0x07, | |
290 | TunerStepDecrement = 0x06, | |
291 | TunerStepIncrement = 0x05, | |
292 | DeviceVendorId = 0x87, | |
293 | GiveDeviceVendorId = 0x8C, | |
294 | VendorCommand = 0x89, | |
295 | VendorCommandWithId = 0xA0, | |
296 | VendorRemoteButtonDown = 0x8A, | |
297 | VendorRemoteButtonUp = 0x8B, | |
298 | SetOsdString = 0x64, | |
299 | GiveOsdName = 0x46, | |
300 | SetOsdName = 0x47, | |
301 | MenuRequest = 0x8D, | |
302 | MenuStatus = 0x8E, | |
303 | UserControlPressed = 0x44, | |
304 | UserControlRelease = 0x45, | |
305 | GiveDevicePowerStatus = 0x8F, | |
306 | ReportPowerStatus = 0x90, | |
307 | FeatureAbort = 0x00, | |
308 | Abort = 0xFF, | |
309 | GiveAudioStatus = 0x71, | |
310 | GiveSystemAudioMode = 0x7D, | |
311 | ReportAudioStatus = 0x7A, | |
312 | SetSystemAudioMode = 0x72, | |
313 | SystemAudioModeRequest = 0x70, | |
314 | SystemAudioModeStatus = 0x7E, | |
315 | SetAudioRate = 0x9A, | |
316 | /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */ | |
317 | None = 0xFD | |
318 | }; | |
319 | ||
320 | public enum class CecSystemAudioStatus | |
321 | { | |
322 | Off = 0, | |
323 | On = 1 | |
324 | }; | |
325 | ||
326 | public enum class CecClientVersion | |
327 | { | |
328 | VersionPre1_5 = 0, | |
a8fffd1b LOK |
329 | Version1_5_0 = 0x1500, |
330 | Version1_5_1 = 0x1501 | |
4ef3b314 LOK |
331 | }; |
332 | ||
3efda01a LOK |
333 | public enum class CecServerVersion |
334 | { | |
335 | VersionPre1_5 = 0, | |
a8fffd1b LOK |
336 | Version1_5_0 = 0x1500, |
337 | Version1_5_1 = 0x1501 | |
3efda01a LOK |
338 | }; |
339 | ||
4ef3b314 LOK |
340 | public ref class CecAdapter |
341 | { | |
342 | public: | |
343 | CecAdapter(System::String ^ strPath, System::String ^ strComPort) | |
344 | { | |
345 | Path = strPath; | |
346 | ComPort = strComPort; | |
347 | } | |
348 | ||
349 | property System::String ^ Path; | |
350 | property System::String ^ ComPort; | |
351 | }; | |
352 | ||
353 | public ref class CecDeviceTypeList | |
354 | { | |
355 | public: | |
356 | CecDeviceTypeList(void) | |
357 | { | |
358 | Types = gcnew array<CecDeviceType>(5); | |
359 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) | |
360 | Types[iPtr] = CecDeviceType::Reserved; | |
361 | } | |
362 | ||
363 | property array<CecDeviceType> ^ Types; | |
364 | }; | |
365 | ||
366 | public ref class CecLogicalAddresses | |
367 | { | |
368 | public: | |
369 | CecLogicalAddresses(void) | |
370 | { | |
371 | Addresses = gcnew array<CecLogicalAddress>(16); | |
b7907707 LOK |
372 | Clear(); |
373 | } | |
374 | ||
375 | void Clear(void) | |
376 | { | |
4ef3b314 | 377 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
63851508 | 378 | Addresses[iPtr] = CecLogicalAddress::Unknown; |
4ef3b314 LOK |
379 | } |
380 | ||
381 | bool IsSet(CecLogicalAddress iAddress) | |
382 | { | |
63851508 | 383 | return Addresses[(unsigned int)iAddress] != CecLogicalAddress::Unknown; |
4ef3b314 LOK |
384 | } |
385 | ||
b7907707 LOK |
386 | void Set(CecLogicalAddress iAddress) |
387 | { | |
388 | Addresses[(unsigned int)iAddress] = iAddress; | |
389 | } | |
390 | ||
a9fb46b4 | 391 | property CecLogicalAddress Primary; |
4ef3b314 LOK |
392 | property array<CecLogicalAddress> ^ Addresses; |
393 | }; | |
394 | ||
395 | public ref class CecDatapacket | |
396 | { | |
397 | public: | |
398 | CecDatapacket(void) | |
399 | { | |
400 | Data = gcnew array<uint8_t>(100); | |
401 | Size = 0; | |
402 | } | |
403 | ||
404 | void PushBack(uint8_t data) | |
405 | { | |
406 | if (Size < 100) | |
407 | { | |
408 | Data[Size] = data; | |
409 | Size++; | |
410 | } | |
411 | } | |
412 | ||
413 | property array<uint8_t> ^ Data; | |
414 | property uint8_t Size; | |
415 | }; | |
416 | ||
417 | public ref class CecCommand | |
418 | { | |
419 | public: | |
420 | CecCommand(CecLogicalAddress iInitiator, CecLogicalAddress iDestination, bool bAck, bool bEom, CecOpcode iOpcode, int32_t iTransmitTimeout) | |
421 | { | |
422 | Initiator = iInitiator; | |
423 | Destination = iDestination; | |
424 | Ack = bAck; | |
425 | Eom = bEom; | |
426 | Opcode = iOpcode; | |
427 | OpcodeSet = true; | |
428 | TransmitTimeout = iTransmitTimeout; | |
429 | Parameters = gcnew CecDatapacket; | |
430 | Empty = false; | |
431 | } | |
432 | ||
433 | CecCommand(void) | |
434 | { | |
435 | Initiator = CecLogicalAddress::Unknown; | |
436 | Destination = CecLogicalAddress::Unknown; | |
437 | Ack = false; | |
438 | Eom = false; | |
439 | Opcode = CecOpcode::None; | |
440 | OpcodeSet = false; | |
441 | TransmitTimeout = 0; | |
442 | Parameters = gcnew CecDatapacket; | |
443 | Empty = true; | |
444 | } | |
445 | ||
446 | void PushBack(uint8_t data) | |
447 | { | |
448 | if (Initiator == CecLogicalAddress::Unknown && Destination == CecLogicalAddress::Unknown) | |
449 | { | |
450 | Initiator = (CecLogicalAddress) (data >> 4); | |
451 | Destination = (CecLogicalAddress) (data & 0xF); | |
452 | } | |
453 | else if (!OpcodeSet) | |
454 | { | |
455 | OpcodeSet = true; | |
456 | Opcode = (CecOpcode)data; | |
457 | } | |
458 | else | |
459 | { | |
460 | Parameters->PushBack(data); | |
461 | } | |
462 | } | |
463 | ||
464 | property bool Empty; | |
465 | property CecLogicalAddress Initiator; | |
466 | property CecLogicalAddress Destination; | |
467 | property bool Ack; | |
468 | property bool Eom; | |
469 | property CecOpcode Opcode; | |
470 | property CecDatapacket ^ Parameters; | |
471 | property bool OpcodeSet; | |
472 | property int32_t TransmitTimeout; | |
473 | }; | |
474 | ||
475 | public ref class CecKeypress | |
476 | { | |
477 | public: | |
478 | CecKeypress(int iKeycode, unsigned int iDuration) | |
479 | { | |
480 | Keycode = iKeycode; | |
481 | Duration = iDuration; | |
482 | Empty = false; | |
483 | } | |
484 | ||
485 | CecKeypress(void) | |
486 | { | |
487 | Keycode = 0; | |
488 | Duration = 0; | |
489 | Empty = true; | |
490 | } | |
491 | ||
492 | property bool Empty; | |
493 | property int Keycode; | |
494 | property unsigned int Duration; | |
495 | }; | |
496 | ||
497 | public ref class CecLogMessage | |
498 | { | |
499 | public: | |
500 | CecLogMessage(System::String ^ strMessage, CecLogLevel iLevel, int64_t iTime) | |
501 | { | |
502 | Message = strMessage; | |
503 | Level = iLevel; | |
504 | Time = iTime; | |
505 | Empty = false; | |
506 | } | |
507 | ||
508 | CecLogMessage(void) | |
509 | { | |
510 | Message = ""; | |
511 | Level = CecLogLevel::None; | |
512 | Time = 0; | |
513 | Empty = true; | |
514 | } | |
515 | ||
516 | property bool Empty; | |
517 | property System::String ^Message; | |
518 | property CecLogLevel Level; | |
519 | property int64_t Time; | |
520 | }; | |
521 | ||
32403cc3 LOK |
522 | ref class CecCallbackMethods; //forward |
523 | public ref class LibCECConfiguration | |
524 | { | |
525 | public: | |
526 | LibCECConfiguration(void) | |
527 | { | |
528 | DeviceName = ""; | |
529 | DeviceTypes = gcnew CecDeviceTypeList(); | |
8670c970 | 530 | AutodetectAddress = true; |
32403cc3 LOK |
531 | PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; |
532 | BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE; | |
533 | HDMIPort = CEC_DEFAULT_HDMI_PORT; | |
534 | ClientVersion = CecClientVersion::VersionPre1_5; | |
3efda01a | 535 | ServerVersion = CecServerVersion::VersionPre1_5; |
b7907707 | 536 | TvVendor = CecVendorId::Unknown; |
32403cc3 LOK |
537 | |
538 | GetSettingsFromROM = false; | |
539 | UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1; | |
b7907707 LOK |
540 | ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1; |
541 | ||
542 | WakeDevices = gcnew CecLogicalAddresses(); | |
543 | if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1) | |
544 | WakeDevices->Set(CecLogicalAddress::Tv); | |
545 | ||
546 | PowerOffDevices = gcnew CecLogicalAddresses(); | |
547 | if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1) | |
548 | PowerOffDevices->Set(CecLogicalAddress::Broadcast); | |
549 | ||
32403cc3 LOK |
550 | PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1; |
551 | PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1; | |
a8fffd1b | 552 | SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1; |
32403cc3 LOK |
553 | } |
554 | ||
555 | void SetCallbacks(CecCallbackMethods ^callbacks) | |
556 | { | |
557 | Callbacks = callbacks; | |
558 | } | |
559 | ||
3efda01a LOK |
560 | void Update(const CEC::libcec_configuration &config) |
561 | { | |
562 | DeviceName = gcnew System::String(config.strDeviceName); | |
563 | ||
564 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) | |
565 | DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr]; | |
566 | ||
567 | AutodetectAddress = config.bAutodetectAddress == 1; | |
568 | PhysicalAddress = config.iPhysicalAddress; | |
569 | BaseDevice = (CecLogicalAddress)config.baseDevice; | |
570 | HDMIPort = config.iHDMIPort; | |
571 | ClientVersion = (CecClientVersion)config.clientVersion; | |
572 | ServerVersion = (CecServerVersion)config.serverVersion; | |
573 | TvVendor = (CecVendorId)config.tvVendor; | |
574 | ||
575 | // player specific settings | |
576 | GetSettingsFromROM = config.bGetSettingsFromROM == 1; | |
577 | UseTVMenuLanguage = config.bUseTVMenuLanguage == 1; | |
578 | ActivateSource = config.bActivateSource == 1; | |
579 | ||
580 | WakeDevices->Clear(); | |
581 | for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) | |
582 | if (config.wakeDevices[iPtr]) | |
583 | WakeDevices->Set((CecLogicalAddress)iPtr); | |
584 | ||
585 | PowerOffDevices->Clear(); | |
586 | for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) | |
587 | if (config.powerOffDevices[iPtr]) | |
588 | PowerOffDevices->Set((CecLogicalAddress)iPtr); | |
589 | ||
590 | PowerOffScreensaver = config.bPowerOffScreensaver == 1; | |
591 | PowerOffOnStandby = config.bPowerOffOnStandby == 1; | |
a8fffd1b | 592 | SendInactiveSource = config.bSendInactiveSource == 1; |
3efda01a LOK |
593 | } |
594 | ||
b7907707 LOK |
595 | property System::String ^ DeviceName; |
596 | property CecDeviceTypeList ^ DeviceTypes; | |
8670c970 | 597 | property bool AutodetectAddress; |
b7907707 LOK |
598 | property uint16_t PhysicalAddress; |
599 | property CecLogicalAddress BaseDevice; | |
600 | property uint8_t HDMIPort; | |
601 | property CecClientVersion ClientVersion; | |
3efda01a | 602 | property CecServerVersion ServerVersion; |
b7907707 | 603 | property CecVendorId TvVendor; |
32403cc3 LOK |
604 | |
605 | // player specific settings | |
b7907707 LOK |
606 | property bool GetSettingsFromROM; |
607 | property bool UseTVMenuLanguage; | |
608 | property bool ActivateSource; | |
609 | property CecLogicalAddresses ^WakeDevices; | |
610 | property CecLogicalAddresses ^PowerOffDevices; | |
611 | property bool PowerOffScreensaver; | |
612 | property bool PowerOffOnStandby; | |
a8fffd1b | 613 | property bool SendInactiveSource; |
b7907707 LOK |
614 | |
615 | property CecCallbackMethods ^ Callbacks; | |
32403cc3 LOK |
616 | }; |
617 | ||
4ef3b314 LOK |
618 | // the callback methods are called by unmanaged code, so we need some delegates for this |
619 | #pragma unmanaged | |
620 | // unmanaged callback methods | |
621 | typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message); | |
622 | typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key); | |
623 | typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command); | |
32403cc3 | 624 | typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config); |
4ef3b314 LOK |
625 | |
626 | static LOGCB g_logCB; | |
627 | static KEYCB g_keyCB; | |
628 | static COMMANDCB g_commandCB; | |
32403cc3 | 629 | static CONFIGCB g_configCB; |
4ef3b314 LOK |
630 | static CEC::ICECCallbacks g_cecCallbacks; |
631 | ||
632 | int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message) | |
633 | { | |
634 | if (g_logCB) | |
635 | return g_logCB(message); | |
636 | return 0; | |
637 | } | |
638 | ||
639 | int CecKeyPressCB(void *cbParam, const CEC::cec_keypress &key) | |
640 | { | |
641 | if (g_keyCB) | |
642 | return g_keyCB(key); | |
643 | return 0; | |
644 | } | |
645 | ||
646 | int CecCommandCB(void *cbParam, const CEC::cec_command &command) | |
647 | { | |
648 | if (g_commandCB) | |
649 | return g_commandCB(command); | |
650 | return 0; | |
651 | } | |
652 | ||
32403cc3 LOK |
653 | int CecConfigCB(void *cbParam, const CEC::libcec_configuration &config) |
654 | { | |
655 | if (g_configCB) | |
656 | return g_configCB(config); | |
657 | return 0; | |
658 | } | |
659 | ||
4ef3b314 LOK |
660 | #pragma managed |
661 | // delegates for the unmanaged callback methods | |
662 | public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &); | |
663 | public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &); | |
664 | public delegate int CecCommandManagedDelegate(const CEC::cec_command &); | |
32403cc3 | 665 | public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &); |
4ef3b314 LOK |
666 | |
667 | // callback method interface | |
668 | public ref class CecCallbackMethods | |
669 | { | |
670 | public: | |
11fea069 LOK |
671 | CecCallbackMethods(void) |
672 | { | |
673 | m_bHasCallbacks = false; | |
674 | m_bDelegatesCreated = false; | |
675 | } | |
4ef3b314 LOK |
676 | |
677 | ~CecCallbackMethods(void) | |
678 | { | |
679 | DestroyDelegates(); | |
680 | } | |
681 | ||
682 | protected: | |
683 | !CecCallbackMethods(void) | |
684 | { | |
685 | DestroyDelegates(); | |
686 | } | |
687 | ||
688 | public: | |
dae4328c LOK |
689 | virtual void DisableCallbacks(void) |
690 | { | |
11fea069 | 691 | DestroyDelegates(); |
dae4328c | 692 | } |
11fea069 | 693 | |
4ef3b314 LOK |
694 | virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) |
695 | { | |
11fea069 | 696 | CreateDelegates(); |
4ef3b314 LOK |
697 | if (!m_bHasCallbacks) |
698 | { | |
699 | m_bHasCallbacks = true; | |
700 | m_callbacks = callbacks; | |
701 | return true; | |
702 | } | |
703 | ||
704 | return false; | |
705 | } | |
706 | ||
707 | virtual int ReceiveLogMessage(CecLogMessage ^ message) | |
708 | { | |
709 | return 0; | |
710 | } | |
711 | ||
712 | virtual int ReceiveKeypress(CecKeypress ^ key) | |
713 | { | |
714 | return 0; | |
715 | } | |
716 | ||
717 | virtual int ReceiveCommand(CecCommand ^ command) | |
718 | { | |
719 | return 0; | |
720 | } | |
721 | ||
32403cc3 LOK |
722 | virtual int ConfigurationChanged(LibCECConfiguration ^ config) |
723 | { | |
724 | return 0; | |
725 | } | |
4ef3b314 LOK |
726 | protected: |
727 | // managed callback methods | |
728 | int CecLogMessageManaged(const CEC::cec_log_message &message) | |
729 | { | |
730 | int iReturn(0); | |
731 | if (m_bHasCallbacks) | |
732 | iReturn = m_callbacks->ReceiveLogMessage(gcnew CecLogMessage(gcnew System::String(message.message), (CecLogLevel)message.level, message.time)); | |
733 | return iReturn; | |
734 | } | |
735 | ||
736 | int CecKeyPressManaged(const CEC::cec_keypress &key) | |
737 | { | |
738 | int iReturn(0); | |
739 | if (m_bHasCallbacks) | |
740 | iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress(key.keycode, key.duration)); | |
741 | return iReturn; | |
742 | } | |
743 | ||
744 | int CecCommandManaged(const CEC::cec_command &command) | |
745 | { | |
746 | int iReturn(0); | |
747 | if (m_bHasCallbacks) | |
748 | { | |
749 | 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); | |
750 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) | |
751 | newCommand->Parameters->PushBack(command.parameters[iPtr]); | |
752 | iReturn = m_callbacks->ReceiveCommand(newCommand); | |
753 | } | |
754 | return iReturn; | |
755 | } | |
756 | ||
32403cc3 LOK |
757 | int CecConfigManaged(const CEC::libcec_configuration &config) |
758 | { | |
759 | int iReturn(0); | |
760 | if (m_bHasCallbacks) | |
761 | { | |
762 | LibCECConfiguration ^netConfig = gcnew LibCECConfiguration(); | |
3efda01a | 763 | netConfig->Update(config); |
32403cc3 LOK |
764 | iReturn = m_callbacks->ConfigurationChanged(netConfig); |
765 | } | |
766 | return iReturn; | |
767 | } | |
768 | ||
4ef3b314 LOK |
769 | void DestroyDelegates() |
770 | { | |
11fea069 LOK |
771 | m_bHasCallbacks = false; |
772 | if (m_bDelegatesCreated) | |
006b76b9 | 773 | { |
11fea069 | 774 | m_bDelegatesCreated = false; |
006b76b9 LOK |
775 | m_logMessageGCHandle.Free(); |
776 | m_keypressGCHandle.Free(); | |
777 | m_commandGCHandle.Free(); | |
778 | } | |
4ef3b314 LOK |
779 | } |
780 | ||
11fea069 LOK |
781 | void CreateDelegates() |
782 | { | |
783 | DestroyDelegates(); | |
784 | ||
785 | if (!m_bDelegatesCreated) | |
786 | { | |
787 | msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context(); | |
788 | ||
789 | // create the delegate method for the log message callback | |
790 | m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged); | |
791 | m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate); | |
792 | g_logCB = static_cast<LOGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer()); | |
793 | g_cecCallbacks.CBCecLogMessage = CecLogMessageCB; | |
794 | ||
795 | // create the delegate method for the keypress callback | |
796 | m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged); | |
797 | m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate); | |
798 | g_keyCB = static_cast<KEYCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer()); | |
799 | g_cecCallbacks.CBCecKeyPress = CecKeyPressCB; | |
800 | ||
801 | // create the delegate method for the command callback | |
802 | m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged); | |
803 | m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate); | |
804 | g_commandCB = static_cast<COMMANDCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer()); | |
805 | g_cecCallbacks.CBCecCommand = CecCommandCB; | |
806 | ||
807 | // create the delegate method for the configuration change callback | |
808 | m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged); | |
809 | m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate); | |
810 | g_configCB = static_cast<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer()); | |
811 | g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB; | |
812 | ||
813 | delete context; | |
814 | m_bDelegatesCreated = true; | |
815 | } | |
816 | } | |
817 | ||
4ef3b314 LOK |
818 | CecLogMessageManagedDelegate ^ m_logMessageDelegate; |
819 | static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle; | |
820 | LOGCB m_logMessageCallback; | |
821 | ||
822 | CecKeyPressManagedDelegate ^ m_keypressDelegate; | |
823 | static System::Runtime::InteropServices::GCHandle m_keypressGCHandle; | |
824 | KEYCB m_keypressCallback; | |
825 | ||
826 | CecCommandManagedDelegate ^ m_commandDelegate; | |
827 | static System::Runtime::InteropServices::GCHandle m_commandGCHandle; | |
828 | COMMANDCB m_commandCallback; | |
829 | ||
32403cc3 LOK |
830 | CecConfigManagedDelegate ^ m_configDelegate; |
831 | static System::Runtime::InteropServices::GCHandle m_configGCHandle; | |
832 | CONFIGCB m_configCallback; | |
833 | ||
4ef3b314 LOK |
834 | CecCallbackMethods ^ m_callbacks; |
835 | bool m_bHasCallbacks; | |
11fea069 | 836 | bool m_bDelegatesCreated; |
4ef3b314 | 837 | }; |
4ef3b314 | 838 | } |