| 1 | /* |
| 2 | * This file is part of the libCEC(R) library. |
| 3 | * |
| 4 | * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. |
| 5 | * libCEC(R) is an original work, containing original code. |
| 6 | * |
| 7 | * libCEC(R) is a trademark of Pulse-Eight Limited. |
| 8 | * |
| 9 | * This program is dual-licensed; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | * |
| 23 | * |
| 24 | * Alternatively, you can license this library under a commercial license, |
| 25 | * please contact Pulse-Eight Licensing for more information. |
| 26 | * |
| 27 | * For more information contact: |
| 28 | * Pulse-Eight Licensing <license@pulse-eight.com> |
| 29 | * http://www.pulse-eight.com/ |
| 30 | * http://www.pulse-eight.net/ |
| 31 | */ |
| 32 | |
| 33 | using System; |
| 34 | using CecSharp; |
| 35 | |
| 36 | namespace LibCECTray.controller.actions |
| 37 | { |
| 38 | internal enum UpdateEventType |
| 39 | { |
| 40 | ProcessCompleted, |
| 41 | StatusText, |
| 42 | ProgressBar, |
| 43 | TVVendorId, |
| 44 | BaseDevicePhysicalAddress, |
| 45 | BaseDevice, |
| 46 | HDMIPort, |
| 47 | PhysicalAddress, |
| 48 | HasAVRDevice, |
| 49 | AVRVendorId, |
| 50 | Configuration, |
| 51 | PollDevices, |
| 52 | ExitApplication |
| 53 | } |
| 54 | |
| 55 | class UpdateEvent : EventArgs |
| 56 | { |
| 57 | public UpdateEvent(UpdateEventType type) |
| 58 | { |
| 59 | Type = type; |
| 60 | } |
| 61 | |
| 62 | public UpdateEvent(UpdateEventType type, bool value) |
| 63 | { |
| 64 | Type = type; |
| 65 | BoolValue = value; |
| 66 | } |
| 67 | |
| 68 | public UpdateEvent(UpdateEventType type, int value) |
| 69 | { |
| 70 | Type = type; |
| 71 | IntValue = value; |
| 72 | } |
| 73 | |
| 74 | public UpdateEvent(UpdateEventType type, string value) |
| 75 | { |
| 76 | Type = type; |
| 77 | StringValue = value; |
| 78 | } |
| 79 | |
| 80 | public UpdateEvent(LibCECConfiguration config) |
| 81 | { |
| 82 | Type = UpdateEventType.Configuration; |
| 83 | ConfigValue = config; |
| 84 | } |
| 85 | |
| 86 | public UpdateEventType Type; |
| 87 | public bool BoolValue; |
| 88 | public int IntValue = -1; |
| 89 | public string StringValue = String.Empty; |
| 90 | public LibCECConfiguration ConfigValue; |
| 91 | } |
| 92 | |
| 93 | internal abstract class UpdateProcess |
| 94 | { |
| 95 | public void SendEvent(UpdateEventType type) |
| 96 | { |
| 97 | if (EventHandler != null) |
| 98 | EventHandler(this, new UpdateEvent(type)); |
| 99 | } |
| 100 | |
| 101 | public void SendEvent(UpdateEventType type, bool value) |
| 102 | { |
| 103 | if (EventHandler != null) |
| 104 | EventHandler(this, new UpdateEvent(type, value)); |
| 105 | } |
| 106 | |
| 107 | public void SendEvent(UpdateEventType type, int value) |
| 108 | { |
| 109 | if (EventHandler != null) |
| 110 | EventHandler(this, new UpdateEvent(type, value)); |
| 111 | } |
| 112 | |
| 113 | public void SendEvent(UpdateEventType type, string value) |
| 114 | { |
| 115 | if (EventHandler != null) |
| 116 | EventHandler(this, new UpdateEvent(type, value)); |
| 117 | } |
| 118 | |
| 119 | public void SendEvent(LibCECConfiguration config) |
| 120 | { |
| 121 | if (EventHandler != null) |
| 122 | EventHandler(this, new UpdateEvent(config)); |
| 123 | } |
| 124 | |
| 125 | public void Run() |
| 126 | { |
| 127 | Process(); |
| 128 | SendEvent(UpdateEventType.ProcessCompleted, true); |
| 129 | } |
| 130 | |
| 131 | public abstract void Process(); |
| 132 | public event EventHandler<UpdateEvent> EventHandler; |
| 133 | } |
| 134 | } |