| 1 | using System; |
| 2 | using CecSharp; |
| 3 | |
| 4 | namespace CecConfigGui |
| 5 | { |
| 6 | public enum UpdateEventType |
| 7 | { |
| 8 | ProcessCompleted, |
| 9 | StatusText, |
| 10 | ProgressBar, |
| 11 | TVVendorId, |
| 12 | BaseDevicePhysicalAddress, |
| 13 | BaseDevice, |
| 14 | HDMIPort, |
| 15 | PhysicalAddress, |
| 16 | HasAVRDevice, |
| 17 | AVRVendorId, |
| 18 | Configuration, |
| 19 | MenuLanguage, |
| 20 | PollDevices, |
| 21 | ExitApplication |
| 22 | } |
| 23 | |
| 24 | public class UpdateEvent : EventArgs |
| 25 | { |
| 26 | public UpdateEvent(UpdateEventType type) |
| 27 | { |
| 28 | Type = type; |
| 29 | } |
| 30 | |
| 31 | public UpdateEvent(UpdateEventType type, bool value) |
| 32 | { |
| 33 | Type = type; |
| 34 | BoolValue = value; |
| 35 | } |
| 36 | |
| 37 | public UpdateEvent(UpdateEventType type, int value) |
| 38 | { |
| 39 | Type = type; |
| 40 | IntValue = value; |
| 41 | } |
| 42 | |
| 43 | public UpdateEvent(UpdateEventType type, string value) |
| 44 | { |
| 45 | Type = type; |
| 46 | StringValue = value; |
| 47 | } |
| 48 | |
| 49 | public UpdateEvent(LibCECConfiguration config) |
| 50 | { |
| 51 | Type = UpdateEventType.Configuration; |
| 52 | ConfigValue = config; |
| 53 | } |
| 54 | |
| 55 | public UpdateEventType Type; |
| 56 | public bool BoolValue = false; |
| 57 | public int IntValue = -1; |
| 58 | public string StringValue = String.Empty; |
| 59 | public LibCECConfiguration ConfigValue = null; |
| 60 | } |
| 61 | |
| 62 | public abstract class UpdateProcess |
| 63 | { |
| 64 | public void SendEvent(UpdateEventType type) |
| 65 | { |
| 66 | EventHandler<UpdateEvent> temp = EventHandler; |
| 67 | if (temp != null) |
| 68 | temp(this, new UpdateEvent(type)); |
| 69 | } |
| 70 | |
| 71 | public void SendEvent(UpdateEventType type, bool value) |
| 72 | { |
| 73 | EventHandler<UpdateEvent> temp = EventHandler; |
| 74 | if (temp != null) |
| 75 | temp(this, new UpdateEvent(type, value)); |
| 76 | } |
| 77 | |
| 78 | public void SendEvent(UpdateEventType type, int value) |
| 79 | { |
| 80 | EventHandler<UpdateEvent> temp = EventHandler; |
| 81 | if (temp != null) |
| 82 | temp(this, new UpdateEvent(type, value)); |
| 83 | } |
| 84 | |
| 85 | public void SendEvent(UpdateEventType type, string value) |
| 86 | { |
| 87 | EventHandler<UpdateEvent> temp = EventHandler; |
| 88 | if (temp != null) |
| 89 | temp(this, new UpdateEvent(type, value)); |
| 90 | } |
| 91 | |
| 92 | public void SendEvent(LibCECConfiguration config) |
| 93 | { |
| 94 | EventHandler<UpdateEvent> temp = EventHandler; |
| 95 | if (temp != null) |
| 96 | temp(this, new UpdateEvent(config)); |
| 97 | } |
| 98 | |
| 99 | public void Run() |
| 100 | { |
| 101 | Process(); |
| 102 | SendEvent(UpdateEventType.ProcessCompleted, true); |
| 103 | } |
| 104 | |
| 105 | public abstract void Process(); |
| 106 | public event EventHandler<UpdateEvent> EventHandler; |
| 107 | } |
| 108 | } |