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