Commit | Line | Data |
---|---|---|
4ef3b314 LOK |
1 | #pragma once |
2 | /* | |
f9717bcc LOK |
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 | */ | |
4ef3b314 | 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 | ||
42 | namespace CecSharp | |
43 | { | |
f9717bcc LOK |
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 | ||
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 | ||
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, | |
251 | SamsungReturn = 0x91, | |
252 | Unknown | |
253 | }; | |
254 | ||
255 | public enum class CecVendorId | |
256 | { | |
257 | Samsung = 0x0000F0, | |
258 | LG = 0x00E091, | |
259 | Panasonic = 0x008045, | |
260 | Pioneer = 0x00E036, | |
261 | Onkyo = 0x0009B0, | |
262 | Yamaha = 0x00A0DE, | |
263 | Philips = 0x00903E, | |
264 | Sony = 0x080046, | |
265 | Toshiba = 0x000039, | |
266 | Akai = 0x0020C7, | |
267 | Benq = 0x8065E9, | |
268 | Daewoo = 0x009053, | |
269 | Grundig = 0x00D0D5, | |
270 | Medion = 0x000CB8, | |
271 | Sharp = 0x08001F, | |
272 | Vizio = 0x6B746D, | |
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, | |
362 | Version1_5_0 = 0x1500, | |
363 | Version1_5_1 = 0x1501, | |
364 | Version1_5_2 = 0x1502, | |
365 | Version1_5_3 = 0x1503, | |
366 | Version1_6_0 = 0x1600, | |
367 | Version1_6_1 = 0x1601, | |
368 | Version1_6_2 = 0x1602, | |
369 | Version1_6_3 = 0x1603, | |
370 | Version1_7_0 = 0x1700, | |
371 | Version1_7_1 = 0x1701, | |
372 | Version1_7_2 = 0x1702, | |
373 | Version1_8_0 = 0x1800, | |
374 | Version1_8_1 = 0x1801, | |
375 | Version1_8_2 = 0x1802, | |
376 | Version1_9_0 = 0x1900 | |
377 | }; | |
378 | ||
379 | public enum class CecServerVersion | |
380 | { | |
381 | VersionPre1_5 = 0, | |
382 | Version1_5_0 = 0x1500, | |
383 | Version1_5_1 = 0x1501, | |
384 | Version1_5_2 = 0x1502, | |
385 | Version1_5_3 = 0x1503, | |
386 | Version1_6_0 = 0x1600, | |
387 | Version1_6_1 = 0x1601, | |
388 | Version1_6_2 = 0x1602, | |
389 | Version1_6_3 = 0x1603, | |
390 | Version1_7_0 = 0x1700, | |
391 | Version1_7_1 = 0x1701, | |
392 | Version1_7_2 = 0x1702, | |
393 | Version1_8_0 = 0x1800, | |
394 | Version1_8_1 = 0x1801, | |
395 | Version1_8_2 = 0x1802, | |
396 | Version1_9_0 = 0x1900 | |
397 | }; | |
398 | ||
399 | /// <summary> | |
400 | /// Descriptor of a CEC adapter, | |
401 | /// </summary> | |
402 | public ref class CecAdapter | |
403 | { | |
404 | public: | |
405 | /// <summary> | |
406 | /// Create a new CEC adapter descriptor | |
407 | /// </summary> | |
408 | /// <param name="path"> The path descriptor for this CEC adapter</param> | |
409 | /// <param name="comPort">The COM port of this CEC adapter</param> | |
410 | CecAdapter(System::String ^ path, System::String ^ comPort) | |
411 | { | |
412 | Path = path; | |
413 | ComPort = comPort; | |
414 | } | |
415 | ||
416 | /// <summary> | |
417 | /// The path descriptor for this CEC adapter | |
418 | /// </summary> | |
419 | property System::String ^ Path; | |
420 | ||
421 | /// <summary> | |
422 | /// The COM port of this CEC adapter | |
423 | /// </summary> | |
424 | property System::String ^ ComPort; | |
425 | }; | |
426 | ||
427 | /// <summary> | |
428 | /// A list of CEC device types | |
429 | /// </summary> | |
430 | public ref class CecDeviceTypeList | |
431 | { | |
432 | public: | |
433 | /// <summary> | |
434 | /// Create a new empty list of CEC device types | |
435 | /// </summary> | |
436 | CecDeviceTypeList(void) | |
437 | { | |
438 | Types = gcnew array<CecDeviceType>(5); | |
439 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) | |
440 | Types[iPtr] = CecDeviceType::Reserved; | |
441 | } | |
442 | ||
443 | /// <summary> | |
444 | /// The array with CecDeviceType instances in this list. | |
445 | /// </summary> | |
446 | property array<CecDeviceType> ^ Types; | |
447 | }; | |
448 | ||
449 | /// <summary> | |
450 | /// A list of logical addresses | |
451 | /// </summary> | |
452 | public ref class CecLogicalAddresses | |
453 | { | |
454 | public: | |
455 | /// <summary> | |
456 | /// Create a new empty list of logical addresses | |
457 | /// </summary> | |
458 | CecLogicalAddresses(void) | |
459 | { | |
460 | Addresses = gcnew array<CecLogicalAddress>(16); | |
461 | Clear(); | |
462 | } | |
463 | ||
464 | /// <summary> | |
465 | /// Clears this list | |
466 | /// </summary> | |
467 | void Clear(void) | |
468 | { | |
469 | Primary = CecLogicalAddress::Unknown; | |
470 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) | |
471 | Addresses[iPtr] = CecLogicalAddress::Unknown; | |
472 | } | |
473 | ||
474 | /// <summary> | |
475 | /// Checks whether a logical address is set in this list. | |
476 | /// </summary> | |
477 | /// <param name="address">The address to check.</param> | |
478 | /// <returns>True when set, false otherwise</returns> | |
479 | bool IsSet(CecLogicalAddress address) | |
480 | { | |
481 | return Addresses[(unsigned int)address] != CecLogicalAddress::Unknown; | |
482 | } | |
483 | ||
484 | /// <summary> | |
485 | /// Add a logical address to this list (if it's not set already) | |
486 | /// </summary> | |
487 | /// <param name="address">The address to add.</param> | |
488 | void Set(CecLogicalAddress address) | |
489 | { | |
490 | Addresses[(unsigned int)address] = address; | |
491 | if (Primary == CecLogicalAddress::Unknown) | |
492 | Primary = address; | |
493 | } | |
494 | ||
495 | /// <summary> | |
496 | /// The primary (first) address in this list | |
497 | /// </summary> | |
498 | property CecLogicalAddress Primary; | |
499 | ||
500 | /// <summary> | |
501 | /// The list of addresses | |
502 | /// </summary> | |
503 | property array<CecLogicalAddress> ^ Addresses; | |
504 | }; | |
505 | ||
506 | ||
507 | /// <summary> | |
508 | /// Byte array used for CEC command parameters | |
509 | /// </summary> | |
510 | public ref class CecDatapacket | |
511 | { | |
512 | public: | |
513 | /// <summary> | |
514 | /// Create a new byte array with maximum size 100 | |
515 | /// </summary> | |
516 | CecDatapacket(void) | |
517 | { | |
518 | Data = gcnew array<uint8_t>(100); | |
519 | Size = 0; | |
520 | } | |
521 | ||
522 | /// <summary> | |
523 | /// Adds a byte to this byte array | |
524 | /// </summary> | |
525 | /// <param name="data">The byte to add.</param> | |
526 | void PushBack(uint8_t data) | |
527 | { | |
528 | if (Size < 100) | |
529 | { | |
530 | Data[Size] = data; | |
531 | Size++; | |
532 | } | |
533 | } | |
534 | ||
535 | /// <summary> | |
536 | /// Array data | |
537 | /// </summary> | |
538 | property array<uint8_t> ^ Data; | |
539 | ||
540 | /// <summary> | |
541 | /// Current data size | |
542 | /// </summary> | |
543 | property uint8_t Size; | |
544 | }; | |
545 | ||
546 | /// <summary> | |
547 | /// A CEC command that is received or transmitted over the CEC bus | |
548 | /// </summary> | |
549 | public ref class CecCommand | |
550 | { | |
551 | public: | |
552 | /// <summary> | |
553 | /// Create a new CEC command instance | |
554 | /// </summary> | |
555 | /// <param name="initiator">The initiator of the command</param> | |
556 | /// <param name="destination">The receiver of the command</param> | |
557 | /// <param name="ack">True when the ack bit is set, false otherwise</param> | |
558 | /// <param name="eom">True when the eom bit is set, false otherwise</param> | |
559 | /// <param name="opcode">The CEC opcode of this command</param> | |
560 | /// <param name="transmitTimeout">The timeout to use when transmitting a command</param> | |
561 | CecCommand(CecLogicalAddress initiator, CecLogicalAddress destination, bool ack, bool eom, CecOpcode opcode, int32_t transmitTimeout) | |
562 | { | |
563 | Initiator = initiator; | |
564 | Destination = destination; | |
565 | Ack = ack; | |
566 | Eom = eom; | |
567 | Opcode = opcode; | |
568 | OpcodeSet = true; | |
569 | TransmitTimeout = transmitTimeout; | |
570 | Parameters = gcnew CecDatapacket; | |
571 | Empty = false; | |
572 | } | |
573 | ||
574 | /// <summary> | |
575 | /// Create a new empty CEC command instance | |
576 | /// </summary> | |
577 | CecCommand(void) | |
578 | { | |
579 | Initiator = CecLogicalAddress::Unknown; | |
580 | Destination = CecLogicalAddress::Unknown; | |
581 | Ack = false; | |
582 | Eom = false; | |
583 | Opcode = CecOpcode::None; | |
584 | OpcodeSet = false; | |
585 | TransmitTimeout = 0; | |
586 | Parameters = gcnew CecDatapacket; | |
587 | Empty = true; | |
588 | } | |
589 | ||
590 | /// <summary> | |
591 | /// Pushes a byte of data to this CEC command | |
592 | /// </summary> | |
593 | /// <param name="data">The byte to add</param> | |
594 | void PushBack(uint8_t data) | |
595 | { | |
596 | if (Initiator == CecLogicalAddress::Unknown && Destination == CecLogicalAddress::Unknown) | |
597 | { | |
598 | Initiator = (CecLogicalAddress) (data >> 4); | |
599 | Destination = (CecLogicalAddress) (data & 0xF); | |
600 | } | |
601 | else if (!OpcodeSet) | |
602 | { | |
603 | OpcodeSet = true; | |
604 | Opcode = (CecOpcode)data; | |
605 | } | |
606 | else | |
607 | { | |
608 | Parameters->PushBack(data); | |
609 | } | |
610 | } | |
611 | ||
612 | /// <summary> | |
613 | /// True when this command is empty, false otherwise. | |
614 | /// </summary> | |
615 | property bool Empty; | |
616 | /// <summary> | |
617 | /// The initiator of the command | |
618 | /// </summary> | |
619 | property CecLogicalAddress Initiator; | |
620 | /// <summary> | |
621 | /// The destination of the command | |
622 | /// </summary> | |
623 | property CecLogicalAddress Destination; | |
624 | /// <summary> | |
625 | /// True when the ack bit is set, false otherwise | |
626 | /// </summary> | |
627 | property bool Ack; | |
628 | /// <summary> | |
629 | /// True when the eom bit is set, false otherwise | |
630 | /// </summary> | |
631 | property bool Eom; | |
632 | /// <summary> | |
633 | /// The CEC opcode of the command | |
634 | /// </summary> | |
635 | property CecOpcode Opcode; | |
636 | /// <summary> | |
637 | /// The parameters of this command | |
638 | /// </summary> | |
639 | property CecDatapacket ^ Parameters; | |
640 | /// <summary> | |
641 | /// True when an opcode is set, false otherwise (poll message) | |
642 | /// </summary> | |
643 | property bool OpcodeSet; | |
644 | /// <summary> | |
645 | /// The timeout to use when transmitting a command | |
646 | /// </summary> | |
647 | property int32_t TransmitTimeout; | |
648 | }; | |
649 | ||
650 | /// <summary> | |
651 | /// A key press that was received | |
652 | /// </summary> | |
653 | public ref class CecKeypress | |
654 | { | |
655 | public: | |
656 | /// <summary> | |
657 | /// Create a new key press instance | |
658 | /// </summary> | |
659 | /// <param name="keycode">The key code of this key press</param> | |
660 | /// <param name="duration">The duration of this key press in milliseconds</param> | |
661 | CecKeypress(CecUserControlCode keycode, unsigned int duration) | |
662 | { | |
663 | Keycode = keycode; | |
664 | Duration = duration; | |
665 | Empty = false; | |
666 | } | |
667 | ||
668 | /// <summary> | |
669 | /// Create a new empty key press instance | |
670 | /// </summary> | |
671 | CecKeypress(void) | |
672 | { | |
673 | Keycode = CecUserControlCode::Unknown; | |
674 | Duration = 0; | |
675 | Empty = true; | |
676 | } | |
677 | ||
678 | /// <summary> | |
679 | /// True when empty, false otherwise | |
680 | /// </summary> | |
681 | property bool Empty; | |
682 | /// <summary> | |
683 | /// The key code of this key press | |
684 | /// </summary> | |
685 | property CecUserControlCode Keycode; | |
686 | /// <summary> | |
687 | /// The duration of this key press in milliseconds | |
688 | /// </summary> | |
689 | property unsigned int Duration; | |
690 | }; | |
691 | ||
692 | /// <summary> | |
693 | /// A log message that libCEC generated | |
694 | /// </summary> | |
695 | public ref class CecLogMessage | |
696 | { | |
697 | public: | |
698 | /// <summary> | |
699 | /// Create a new log message | |
700 | /// </summary> | |
701 | /// <param name="message">The actual message</param> | |
702 | /// <param name="level">The log level, so the application can choose what type information to display</param> | |
703 | /// <param name="time">The timestamp of this message, in milliseconds after connecting</param> | |
704 | CecLogMessage(System::String ^ message, CecLogLevel level, int64_t time) | |
705 | { | |
706 | Message = message; | |
707 | Level = level; | |
708 | Time = time; | |
709 | Empty = false; | |
710 | } | |
711 | ||
712 | /// <summary> | |
713 | /// Create a new empty log message | |
714 | /// </summary> | |
715 | CecLogMessage(void) | |
716 | { | |
717 | Message = ""; | |
718 | Level = CecLogLevel::None; | |
719 | Time = 0; | |
720 | Empty = true; | |
721 | } | |
722 | ||
723 | /// <summary> | |
724 | /// True when empty, false otherwise. | |
725 | /// </summary> | |
726 | property bool Empty; | |
727 | /// <summary> | |
728 | /// The actual message | |
729 | /// </summary> | |
730 | property System::String ^Message; | |
731 | /// <summary> | |
732 | /// The log level, so the application can choose what type information to display | |
733 | /// </summary> | |
734 | property CecLogLevel Level; | |
735 | /// <summary> | |
736 | /// The timestamp of this message, in milliseconds after connecting | |
737 | /// </summary> | |
738 | property int64_t Time; | |
739 | }; | |
740 | ||
741 | ref class CecCallbackMethods; //forward declaration | |
742 | ||
743 | /// <summary> | |
744 | /// The configuration that libCEC uses. | |
745 | /// </summary> | |
746 | public ref class LibCECConfiguration | |
747 | { | |
748 | public: | |
749 | /// <summary> | |
750 | /// Create a new configuration instance with default settings. | |
751 | /// </summary> | |
752 | LibCECConfiguration(void) | |
753 | { | |
754 | DeviceName = ""; | |
755 | DeviceTypes = gcnew CecDeviceTypeList(); | |
756 | AutodetectAddress = true; | |
757 | PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; | |
758 | BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE; | |
759 | HDMIPort = CEC_DEFAULT_HDMI_PORT; | |
760 | ClientVersion = CecClientVersion::VersionPre1_5; | |
761 | ServerVersion = CecServerVersion::VersionPre1_5; | |
762 | TvVendor = CecVendorId::Unknown; | |
763 | ||
764 | GetSettingsFromROM = false; | |
765 | UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1; | |
766 | ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1; | |
767 | ||
768 | WakeDevices = gcnew CecLogicalAddresses(); | |
769 | if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1) | |
770 | WakeDevices->Set(CecLogicalAddress::Tv); | |
771 | ||
772 | PowerOffDevices = gcnew CecLogicalAddresses(); | |
773 | if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1) | |
774 | PowerOffDevices->Set(CecLogicalAddress::Broadcast); | |
775 | ||
776 | PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1; | |
777 | PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1; | |
778 | ||
779 | SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1; | |
780 | LogicalAddresses = gcnew CecLogicalAddresses(); | |
781 | FirmwareVersion = 1; | |
782 | PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1; | |
783 | ShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1; | |
784 | DeviceLanguage = ""; | |
785 | } | |
786 | ||
787 | /// <summary> | |
788 | /// Change the callback method pointers in this configuration instance. | |
789 | /// </summary> | |
790 | /// <param name="callbacks">The new callbacks</param> | |
791 | void SetCallbacks(CecCallbackMethods ^callbacks) | |
792 | { | |
793 | Callbacks = callbacks; | |
794 | } | |
795 | ||
796 | /// <summary> | |
797 | /// Update this configuration with data received from libCEC | |
798 | /// </summary> | |
799 | /// <param name="config">The configuration that was received from libCEC</param> | |
800 | void Update(const CEC::libcec_configuration &config) | |
801 | { | |
802 | DeviceName = gcnew System::String(config.strDeviceName); | |
803 | ||
804 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) | |
805 | DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr]; | |
806 | ||
807 | AutodetectAddress = config.bAutodetectAddress == 1; | |
808 | PhysicalAddress = config.iPhysicalAddress; | |
809 | BaseDevice = (CecLogicalAddress)config.baseDevice; | |
810 | HDMIPort = config.iHDMIPort; | |
811 | ClientVersion = (CecClientVersion)config.clientVersion; | |
812 | ServerVersion = (CecServerVersion)config.serverVersion; | |
813 | TvVendor = (CecVendorId)config.tvVendor; | |
814 | ||
815 | // player specific settings | |
816 | GetSettingsFromROM = config.bGetSettingsFromROM == 1; | |
817 | UseTVMenuLanguage = config.bUseTVMenuLanguage == 1; | |
818 | ActivateSource = config.bActivateSource == 1; | |
819 | ||
820 | WakeDevices->Clear(); | |
821 | for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) | |
822 | if (config.wakeDevices[iPtr]) | |
823 | WakeDevices->Set((CecLogicalAddress)iPtr); | |
824 | ||
825 | PowerOffDevices->Clear(); | |
826 | for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) | |
827 | if (config.powerOffDevices[iPtr]) | |
828 | PowerOffDevices->Set((CecLogicalAddress)iPtr); | |
829 | ||
830 | PowerOffScreensaver = config.bPowerOffScreensaver == 1; | |
831 | PowerOffOnStandby = config.bPowerOffOnStandby == 1; | |
832 | ||
833 | if (ServerVersion >= CecServerVersion::Version1_5_1) | |
834 | SendInactiveSource = config.bSendInactiveSource == 1; | |
835 | ||
836 | if (ServerVersion >= CecServerVersion::Version1_5_3) | |
837 | { | |
838 | LogicalAddresses->Clear(); | |
839 | for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) | |
840 | if (config.logicalAddresses[iPtr]) | |
841 | LogicalAddresses->Set((CecLogicalAddress)iPtr); | |
842 | } | |
843 | ||
844 | if (ServerVersion >= CecServerVersion::Version1_6_0) | |
845 | { | |
846 | FirmwareVersion = config.iFirmwareVersion; | |
847 | PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1; | |
848 | ShutdownOnStandby = config.bShutdownOnStandby == 1; | |
849 | } | |
850 | ||
851 | if (ServerVersion >= CecServerVersion::Version1_6_2) | |
852 | DeviceLanguage = gcnew System::String(config.strDeviceLanguage); | |
853 | ||
854 | if (ServerVersion >= CecServerVersion::Version1_6_3) | |
855 | MonitorOnlyClient = config.bMonitorOnly == 1; | |
856 | } | |
857 | ||
858 | /// <summary> | |
859 | /// The device name to use on the CEC bus | |
860 | /// </summary> | |
861 | property System::String ^ DeviceName; | |
862 | ||
863 | /// <summary> | |
864 | /// The device type(s) to use on the CEC bus for libCEC | |
865 | /// </summary> | |
866 | property CecDeviceTypeList ^ DeviceTypes; | |
867 | ||
868 | /// <summary> | |
869 | /// True to try to autodetect the physical address, false otherwise | |
870 | /// </summary> | |
871 | property bool AutodetectAddress; | |
872 | ||
873 | /// <summary> | |
874 | /// The physical address that libCEC uses on the CEC bus | |
875 | /// </summary> | |
876 | property uint16_t PhysicalAddress; | |
877 | ||
878 | /// <summary> | |
879 | /// The logical address of the device to which the CEC adapter is connected, only used when PhysicalAddress isn't set | |
880 | /// </summary> | |
881 | property CecLogicalAddress BaseDevice; | |
882 | ||
883 | /// <summary> | |
884 | /// The hdmi port number on the device to which the CEC adapter is connected, only used when PhysicalAddress isn't set | |
885 | /// </summary> | |
886 | property uint8_t HDMIPort; | |
887 | ||
888 | /// <summary> | |
889 | /// The client API version to use | |
890 | /// </summary> | |
891 | property CecClientVersion ClientVersion; | |
892 | ||
893 | /// <summary> | |
894 | /// The version of libCEC | |
895 | /// </summary> | |
896 | property CecServerVersion ServerVersion; | |
897 | ||
898 | /// <summary> | |
899 | /// Override the vendor ID of the TV when set (for quirks mode) | |
900 | /// </summary> | |
901 | property CecVendorId TvVendor; | |
902 | ||
903 | /// <summary> | |
904 | /// True to read the settings from the EEPROM, which possibly override the settings passed here | |
905 | /// </summary> | |
906 | property bool GetSettingsFromROM; | |
907 | ||
908 | /// <summary> | |
909 | /// Use the language setting of the TV in the client application. Must be implemented by the client application. | |
910 | /// </summary> | |
911 | property bool UseTVMenuLanguage; | |
912 | ||
913 | /// <summary> | |
914 | /// Make libCEC the active source when starting the client application | |
915 | /// </summary> | |
916 | property bool ActivateSource; | |
917 | ||
918 | /// <summary> | |
919 | /// List of devices to send a power on command to when starting the client application | |
920 | /// </summary> | |
921 | property CecLogicalAddresses ^WakeDevices; | |
922 | ||
923 | /// <summary> | |
924 | /// List of devices to send a standby command to when exiting the client application | |
925 | /// </summary> | |
926 | property CecLogicalAddresses ^PowerOffDevices; | |
927 | ||
928 | /// <summary> | |
929 | /// Send standby commands when the client application activates the screensaver. Must be implemented by the client application. | |
930 | /// </summary> | |
931 | property bool PowerOffScreensaver; | |
932 | ||
933 | /// <summary> | |
934 | /// Power off the PC when the TV powers off. Must be implemented by the client application. | |
935 | /// </summary> | |
936 | property bool PowerOffOnStandby; | |
937 | ||
938 | /// <summary> | |
939 | /// Send an inactive source message when exiting the client application. | |
940 | /// </summary> | |
941 | property bool SendInactiveSource; | |
942 | ||
943 | /// <summary> | |
944 | /// The list of logical addresses that libCEC is using | |
945 | /// </summary> | |
946 | property CecLogicalAddresses ^LogicalAddresses; | |
947 | ||
948 | /// <summary> | |
949 | /// The firmware version of the adapter to which libCEC is connected | |
950 | /// </summary> | |
951 | property uint16_t FirmwareVersion; | |
952 | ||
953 | /// <summary> | |
954 | /// Send standby commands when the client application activates standby mode (S3). Must be implemented by the client application. | |
955 | /// </summary> | |
956 | property bool PowerOffDevicesOnStandby; | |
957 | property bool ShutdownOnStandby; | |
958 | ||
959 | /// <summary> | |
960 | /// True to start a monitor-only client, false to start a standard client. | |
961 | /// </summary> | |
962 | property bool MonitorOnlyClient; | |
963 | ||
964 | /// <summary> | |
965 | /// The language code of the menu language that libCEC reports to other devices. | |
966 | /// </summary> | |
967 | property System::String ^ DeviceLanguage; | |
968 | ||
969 | /// <summary> | |
970 | /// The callback methods to use. | |
971 | /// </summary> | |
972 | property CecCallbackMethods ^ Callbacks; | |
973 | }; | |
974 | ||
975 | // the callback methods are called by unmanaged code, so we need some delegates for this | |
976 | #pragma unmanaged | |
977 | // unmanaged callback methods | |
978 | typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message); | |
979 | typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key); | |
980 | typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command); | |
981 | typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config); | |
982 | typedef int (__stdcall *ALERTCB) (const CEC::libcec_alert, const CEC::libcec_parameter &data); | |
983 | typedef int (__stdcall *MENUCB) (const CEC::cec_menu_state newVal); | |
984 | typedef void (__stdcall *ACTICB) (const CEC::cec_logical_address logicalAddress, const uint8_t bActivated); | |
985 | ||
986 | typedef struct | |
987 | { | |
988 | LOGCB logCB; | |
989 | KEYCB keyCB; | |
990 | COMMANDCB commandCB; | |
991 | CONFIGCB configCB; | |
992 | ALERTCB alertCB; | |
993 | MENUCB menuCB; | |
994 | ACTICB sourceActivatedCB; | |
995 | } UnmanagedCecCallbacks; | |
996 | ||
997 | static PLATFORM::CMutex g_callbackMutex; | |
998 | static std::vector<UnmanagedCecCallbacks> g_unmanagedCallbacks; | |
dc6366e8 | 999 | static CEC::ICECCallbacks g_cecCallbacks; |
4ef3b314 | 1000 | |
f9717bcc LOK |
1001 | int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message) |
1002 | { | |
1003 | if (cbParam) | |
1004 | { | |
1005 | size_t iPtr = (size_t)cbParam; | |
1006 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1007 | if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) | |
1008 | return g_unmanagedCallbacks[iPtr].logCB(message); | |
1009 | } | |
1010 | return 0; | |
1011 | } | |
1012 | ||
1013 | int CecKeyPressCB(void *cbParam, const CEC::cec_keypress &key) | |
1014 | { | |
1015 | if (cbParam) | |
1016 | { | |
1017 | size_t iPtr = (size_t)cbParam; | |
1018 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1019 | if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) | |
1020 | return g_unmanagedCallbacks[iPtr].keyCB(key); | |
1021 | } | |
1022 | return 0; | |
1023 | } | |
1024 | ||
1025 | int CecCommandCB(void *cbParam, const CEC::cec_command &command) | |
1026 | { | |
1027 | if (cbParam) | |
1028 | { | |
1029 | size_t iPtr = (size_t)cbParam; | |
1030 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1031 | if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) | |
1032 | return g_unmanagedCallbacks[iPtr].commandCB(command); | |
1033 | } | |
1034 | return 0; | |
1035 | } | |
4ef3b314 | 1036 | |
32403cc3 | 1037 | int CecConfigCB(void *cbParam, const CEC::libcec_configuration &config) |
f9717bcc LOK |
1038 | { |
1039 | if (cbParam) | |
1040 | { | |
1041 | size_t iPtr = (size_t)cbParam; | |
1042 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1043 | if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) | |
1044 | return g_unmanagedCallbacks[iPtr].configCB(config); | |
1045 | } | |
1046 | return 0; | |
1047 | } | |
1048 | ||
1049 | int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter &data) | |
1050 | { | |
1051 | if (cbParam) | |
1052 | { | |
1053 | size_t iPtr = (size_t)cbParam; | |
1054 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1055 | if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) | |
1056 | return g_unmanagedCallbacks[iPtr].alertCB(alert, data); | |
1057 | } | |
1058 | return 0; | |
1059 | } | |
1060 | ||
1061 | int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal) | |
1062 | { | |
1063 | if (cbParam) | |
1064 | { | |
1065 | size_t iPtr = (size_t)cbParam; | |
1066 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1067 | if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) | |
1068 | return g_unmanagedCallbacks[iPtr].menuCB(newVal); | |
1069 | } | |
1070 | return 0; | |
1071 | } | |
dc6366e8 | 1072 | |
f9717bcc LOK |
1073 | void CecSourceActivatedCB(void *cbParam, const CEC::cec_logical_address logicalAddress, const uint8_t bActivated) |
1074 | { | |
1075 | if (cbParam) | |
1076 | { | |
1077 | size_t iPtr = (size_t)cbParam; | |
1078 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1079 | if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) | |
1080 | g_unmanagedCallbacks[iPtr].sourceActivatedCB(logicalAddress, bActivated); | |
1081 | } | |
1082 | } | |
1083 | ||
1084 | #pragma managed | |
1085 | // delegates for the unmanaged callback methods | |
1086 | public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &); | |
1087 | public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &); | |
1088 | public delegate int CecCommandManagedDelegate(const CEC::cec_command &); | |
1089 | public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &); | |
1090 | public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &); | |
1091 | public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state newVal); | |
1092 | public delegate void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated); | |
1093 | ||
1094 | void AssignCallbacks() | |
1095 | { | |
1096 | g_cecCallbacks.CBCecLogMessage = CecLogMessageCB; | |
1097 | g_cecCallbacks.CBCecKeyPress = CecKeyPressCB; | |
1098 | g_cecCallbacks.CBCecCommand = CecCommandCB; | |
1099 | g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB; | |
1100 | g_cecCallbacks.CBCecAlert = CecAlertCB; | |
1101 | g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB; | |
1102 | g_cecCallbacks.CBCecSourceActivated = CecSourceActivatedCB; | |
1103 | } | |
1104 | ||
1105 | /// <summary> | |
1106 | /// The callback methods that libCEC uses | |
1107 | /// </summary> | |
1108 | public ref class CecCallbackMethods | |
1109 | { | |
1110 | public: | |
11fea069 LOK |
1111 | CecCallbackMethods(void) |
1112 | { | |
f9717bcc LOK |
1113 | m_iCallbackPtr = -1; |
1114 | AssignCallbacks(); | |
11fea069 LOK |
1115 | m_bHasCallbacks = false; |
1116 | m_bDelegatesCreated = false; | |
1117 | } | |
4ef3b314 | 1118 | |
f9717bcc | 1119 | ~CecCallbackMethods(void) |
dc6366e8 LOK |
1120 | { |
1121 | DestroyDelegates(); | |
1122 | } | |
1123 | ||
f9717bcc LOK |
1124 | size_t GetCallbackPtr(void) |
1125 | { | |
1126 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1127 | return m_iCallbackPtr; | |
1128 | } | |
1129 | ||
1130 | protected: | |
1131 | !CecCallbackMethods(void) | |
1132 | { | |
1133 | DestroyDelegates(); | |
1134 | } | |
1135 | ||
1136 | public: | |
1137 | virtual void DisableCallbacks(void) | |
1138 | { | |
1139 | DestroyDelegates(); | |
1140 | } | |
1141 | ||
1142 | virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) | |
1143 | { | |
11fea069 | 1144 | CreateDelegates(); |
f9717bcc LOK |
1145 | if (!m_bHasCallbacks) |
1146 | { | |
1147 | m_bHasCallbacks = true; | |
1148 | m_callbacks = callbacks; | |
1149 | return true; | |
1150 | } | |
1151 | ||
1152 | return false; | |
1153 | } | |
1154 | ||
1155 | /// <summary> | |
1156 | /// Called by libCEC to send back a log message to the application | |
1157 | /// </summary> | |
1158 | /// <param name="message">The log message</param> | |
1159 | virtual int ReceiveLogMessage(CecLogMessage ^ message) | |
1160 | { | |
1161 | return 0; | |
1162 | } | |
1163 | ||
1164 | /// <summary> | |
1165 | /// Called by libCEC to send back a key press to the application | |
1166 | /// </summary> | |
1167 | /// <param name="key">The key press command that libCEC received</param> | |
1168 | virtual int ReceiveKeypress(CecKeypress ^ key) | |
1169 | { | |
1170 | return 0; | |
1171 | } | |
1172 | ||
1173 | /// <summary> | |
1174 | /// Called by libCEC to send back raw CEC data to the application | |
1175 | /// </summary> | |
1176 | /// <param name="command">The raw CEC data</param> | |
1177 | virtual int ReceiveCommand(CecCommand ^ command) | |
1178 | { | |
1179 | return 0; | |
1180 | } | |
1181 | ||
1182 | /// <summary> | |
1183 | /// Called by libCEC to send back an updated configuration to the application | |
1184 | /// </summary> | |
1185 | /// <param name="config">The new configuration</param> | |
1186 | virtual int ConfigurationChanged(LibCECConfiguration ^ config) | |
1187 | { | |
1188 | return 0; | |
1189 | } | |
1190 | ||
1191 | /// <summary> | |
1192 | /// Called by libCEC to send back an alert message to the application | |
1193 | /// </summary> | |
1194 | /// <param name="data">The alert message</param> | |
1195 | virtual int ReceiveAlert(CecAlert alert, CecParameter ^ data) | |
1196 | { | |
1197 | return 0; | |
1198 | } | |
1199 | ||
1200 | /// <summary> | |
1201 | /// Called by libCEC to send back a menu stata change to the application | |
1202 | /// </summary> | |
1203 | /// <param name="newVal">The new menu state</param> | |
1204 | virtual int ReceiveMenuStateChange(CecMenuState newVal) | |
1205 | { | |
1206 | return 0; | |
1207 | } | |
1208 | ||
1209 | /// <summary> | |
1210 | /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated | |
1211 | /// </summary> | |
1212 | /// <param name="logicalAddress">The logical address that was (de)activated</param> | |
1213 | /// <param name="activated">True when activated, false when deactivated</param> | |
1214 | virtual void SourceActivated(CecLogicalAddress logicalAddress, bool activated) | |
1215 | { | |
1216 | } | |
1217 | ||
1218 | protected: | |
1219 | // managed callback methods | |
1220 | int CecLogMessageManaged(const CEC::cec_log_message &message) | |
1221 | { | |
1222 | int iReturn(0); | |
1223 | if (m_bHasCallbacks) | |
1224 | iReturn = m_callbacks->ReceiveLogMessage(gcnew CecLogMessage(gcnew System::String(message.message), (CecLogLevel)message.level, message.time)); | |
1225 | return iReturn; | |
1226 | } | |
1227 | ||
1228 | int CecKeyPressManaged(const CEC::cec_keypress &key) | |
1229 | { | |
1230 | int iReturn(0); | |
1231 | if (m_bHasCallbacks) | |
1232 | iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration)); | |
1233 | return iReturn; | |
1234 | } | |
1235 | ||
1236 | int CecCommandManaged(const CEC::cec_command &command) | |
1237 | { | |
1238 | int iReturn(0); | |
1239 | if (m_bHasCallbacks) | |
1240 | { | |
1241 | 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); | |
1242 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) | |
1243 | newCommand->Parameters->PushBack(command.parameters[iPtr]); | |
1244 | iReturn = m_callbacks->ReceiveCommand(newCommand); | |
1245 | } | |
1246 | return iReturn; | |
1247 | } | |
1248 | ||
1249 | int CecConfigManaged(const CEC::libcec_configuration &config) | |
1250 | { | |
1251 | int iReturn(0); | |
1252 | if (m_bHasCallbacks) | |
1253 | { | |
1254 | LibCECConfiguration ^netConfig = gcnew LibCECConfiguration(); | |
1255 | netConfig->Update(config); | |
1256 | iReturn = m_callbacks->ConfigurationChanged(netConfig); | |
1257 | } | |
1258 | return iReturn; | |
1259 | } | |
1260 | ||
1261 | int CecAlertManaged(const CEC::libcec_alert alert, const CEC::libcec_parameter &data) | |
1262 | { | |
1263 | int iReturn(0); | |
1264 | if (m_bHasCallbacks) | |
1265 | { | |
1266 | CecParameterType newType = (CecParameterType)data.paramType; | |
1267 | if (newType == CecParameterType::ParameterTypeString) | |
1268 | { | |
1269 | System::String ^ newData = gcnew System::String((const char *)data.paramData, 0, 128); | |
1270 | CecParameter ^ newParam = gcnew CecParameter(newType, newData); | |
1271 | iReturn = m_callbacks->ReceiveAlert((CecAlert)alert, newParam); | |
1272 | } | |
1273 | } | |
1274 | return iReturn; | |
1275 | } | |
1276 | ||
1277 | int CecMenuManaged(const CEC::cec_menu_state newVal) | |
1278 | { | |
1279 | int iReturn(0); | |
1280 | if (m_bHasCallbacks) | |
1281 | { | |
1282 | iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal); | |
1283 | } | |
1284 | return iReturn; | |
1285 | } | |
1286 | ||
1287 | void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated) | |
1288 | { | |
1289 | if (m_bHasCallbacks) | |
1290 | m_callbacks->SourceActivated((CecLogicalAddress)logicalAddress, bActivated == 1); | |
1291 | } | |
1292 | ||
1293 | void DestroyDelegates() | |
1294 | { | |
11fea069 | 1295 | m_bHasCallbacks = false; |
f9717bcc LOK |
1296 | if (m_bDelegatesCreated) |
1297 | { | |
11fea069 | 1298 | m_bDelegatesCreated = false; |
f9717bcc LOK |
1299 | m_logMessageGCHandle.Free(); |
1300 | m_keypressGCHandle.Free(); | |
1301 | m_commandGCHandle.Free(); | |
1302 | m_alertGCHandle.Free(); | |
1303 | m_menuGCHandle.Free(); | |
1304 | m_sourceActivatedGCHandle.Free(); | |
1305 | } | |
1306 | } | |
4ef3b314 | 1307 | |
11fea069 LOK |
1308 | void CreateDelegates() |
1309 | { | |
1310 | DestroyDelegates(); | |
1311 | ||
1312 | if (!m_bDelegatesCreated) | |
1313 | { | |
1314 | msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context(); | |
1315 | ||
1316 | // create the delegate method for the log message callback | |
dc6366e8 LOK |
1317 | m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged); |
1318 | m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate); | |
f9717bcc | 1319 | m_logMessageCallback = static_cast<LOGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer()); |
11fea069 LOK |
1320 | |
1321 | // create the delegate method for the keypress callback | |
dc6366e8 LOK |
1322 | m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged); |
1323 | m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate); | |
f9717bcc | 1324 | m_keypressCallback = static_cast<KEYCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer()); |
11fea069 LOK |
1325 | |
1326 | // create the delegate method for the command callback | |
dc6366e8 LOK |
1327 | m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged); |
1328 | m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate); | |
f9717bcc | 1329 | m_commandCallback = static_cast<COMMANDCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer()); |
11fea069 LOK |
1330 | |
1331 | // create the delegate method for the configuration change callback | |
dc6366e8 LOK |
1332 | m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged); |
1333 | m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate); | |
f9717bcc | 1334 | m_configCallback = static_cast<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer()); |
11fea069 | 1335 | |
5ee37222 | 1336 | // create the delegate method for the alert callback |
dc6366e8 LOK |
1337 | m_alertDelegate = gcnew CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged); |
1338 | m_alertGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate); | |
f9717bcc | 1339 | m_alertCallback = static_cast<ALERTCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer()); |
5ee37222 | 1340 | |
c3a20edb | 1341 | // create the delegate method for the menu callback |
dc6366e8 LOK |
1342 | m_menuDelegate = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged); |
1343 | m_menuGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate); | |
f9717bcc | 1344 | m_menuCallback = static_cast<MENUCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer()); |
c3a20edb | 1345 | |
f9717bcc | 1346 | // create the delegate method for the source activated callback |
dc6366e8 LOK |
1347 | m_sourceActivatedDelegate = gcnew CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged); |
1348 | m_sourceActivatedGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate); | |
f9717bcc | 1349 | m_sourceActivatedCallback = static_cast<ACTICB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate).ToPointer()); |
29d5198c | 1350 | |
11fea069 | 1351 | delete context; |
dc6366e8 | 1352 | |
f9717bcc LOK |
1353 | UnmanagedCecCallbacks unmanagedCallbacks; |
1354 | unmanagedCallbacks.logCB = m_logMessageCallback; | |
1355 | unmanagedCallbacks.keyCB = m_keypressCallback; | |
1356 | unmanagedCallbacks.commandCB = m_commandCallback; | |
1357 | unmanagedCallbacks.configCB = m_configCallback; | |
1358 | unmanagedCallbacks.alertCB = m_alertCallback; | |
1359 | unmanagedCallbacks.menuCB = m_menuCallback; | |
1360 | unmanagedCallbacks.sourceActivatedCB = m_sourceActivatedCallback; | |
1361 | ||
1362 | PLATFORM::CLockObject lock(g_callbackMutex); | |
1363 | g_unmanagedCallbacks.push_back(unmanagedCallbacks); | |
1364 | m_iCallbackPtr = g_unmanagedCallbacks.size() - 1; | |
1365 | m_bDelegatesCreated = true; | |
11fea069 LOK |
1366 | } |
1367 | } | |
1368 | ||
f9717bcc LOK |
1369 | CecLogMessageManagedDelegate ^ m_logMessageDelegate; |
1370 | static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle; | |
1371 | LOGCB m_logMessageCallback; | |
4ef3b314 | 1372 | |
f9717bcc LOK |
1373 | CecKeyPressManagedDelegate ^ m_keypressDelegate; |
1374 | static System::Runtime::InteropServices::GCHandle m_keypressGCHandle; | |
1375 | KEYCB m_keypressCallback; | |
4ef3b314 | 1376 | |
f9717bcc LOK |
1377 | CecCommandManagedDelegate ^ m_commandDelegate; |
1378 | static System::Runtime::InteropServices::GCHandle m_commandGCHandle; | |
1379 | COMMANDCB m_commandCallback; | |
4ef3b314 | 1380 | |
f9717bcc LOK |
1381 | CecConfigManagedDelegate ^ m_configDelegate; |
1382 | static System::Runtime::InteropServices::GCHandle m_configGCHandle; | |
1383 | CONFIGCB m_configCallback; | |
32403cc3 | 1384 | |
f9717bcc LOK |
1385 | CecAlertManagedDelegate ^ m_alertDelegate; |
1386 | static System::Runtime::InteropServices::GCHandle m_alertGCHandle; | |
1387 | ALERTCB m_alertCallback; | |
5ee37222 | 1388 | |
f9717bcc LOK |
1389 | CecMenuManagedDelegate ^ m_menuDelegate; |
1390 | static System::Runtime::InteropServices::GCHandle m_menuGCHandle; | |
1391 | MENUCB m_menuCallback; | |
c3a20edb | 1392 | |
f9717bcc LOK |
1393 | CecSourceActivatedManagedDelegate ^ m_sourceActivatedDelegate; |
1394 | static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle; | |
1395 | ACTICB m_sourceActivatedCallback; | |
29d5198c | 1396 | |
f9717bcc LOK |
1397 | CecCallbackMethods ^ m_callbacks; |
1398 | bool m_bHasCallbacks; | |
11fea069 | 1399 | bool m_bDelegatesCreated; |
f9717bcc LOK |
1400 | size_t m_iCallbackPtr; |
1401 | }; | |
4ef3b314 | 1402 | } |