| 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 | } |
| 22 | |
| 23 | public class UpdateEvent : EventArgs |
| 24 | { |
| 25 | public UpdateEvent(UpdateEventType type) |
| 26 | { |
| 27 | Type = type; |
| 28 | } |
| 29 | |
| 30 | public UpdateEvent(UpdateEventType type, bool value) |
| 31 | { |
| 32 | Type = type; |
| 33 | BoolValue = value; |
| 34 | } |
| 35 | |
| 36 | public UpdateEvent(UpdateEventType type, int value) |
| 37 | { |
| 38 | Type = type; |
| 39 | IntValue = value; |
| 40 | } |
| 41 | |
| 42 | public UpdateEvent(UpdateEventType type, string value) |
| 43 | { |
| 44 | Type = type; |
| 45 | StringValue = value; |
| 46 | } |
| 47 | |
| 48 | public UpdateEvent(LibCECConfiguration config) |
| 49 | { |
| 50 | Type = UpdateEventType.Configuration; |
| 51 | ConfigValue = config; |
| 52 | } |
| 53 | |
| 54 | public UpdateEventType Type; |
| 55 | public bool BoolValue = false; |
| 56 | public int IntValue = -1; |
| 57 | public string StringValue = String.Empty; |
| 58 | public LibCECConfiguration ConfigValue = null; |
| 59 | } |
| 60 | |
| 61 | public abstract class UpdateProcess |
| 62 | { |
| 63 | public void SendEvent(UpdateEventType type) |
| 64 | { |
| 65 | EventHandler<UpdateEvent> temp = EventHandler; |
| 66 | if (temp != null) |
| 67 | temp(this, new UpdateEvent(type)); |
| 68 | } |
| 69 | |
| 70 | public void SendEvent(UpdateEventType type, bool value) |
| 71 | { |
| 72 | EventHandler<UpdateEvent> temp = EventHandler; |
| 73 | if (temp != null) |
| 74 | temp(this, new UpdateEvent(type, value)); |
| 75 | } |
| 76 | |
| 77 | public void SendEvent(UpdateEventType type, int value) |
| 78 | { |
| 79 | EventHandler<UpdateEvent> temp = EventHandler; |
| 80 | if (temp != null) |
| 81 | temp(this, new UpdateEvent(type, value)); |
| 82 | } |
| 83 | |
| 84 | public void SendEvent(UpdateEventType type, string value) |
| 85 | { |
| 86 | EventHandler<UpdateEvent> temp = EventHandler; |
| 87 | if (temp != null) |
| 88 | temp(this, new UpdateEvent(type, value)); |
| 89 | } |
| 90 | |
| 91 | public void SendEvent(LibCECConfiguration config) |
| 92 | { |
| 93 | EventHandler<UpdateEvent> temp = EventHandler; |
| 94 | if (temp != null) |
| 95 | temp(this, new UpdateEvent(config)); |
| 96 | } |
| 97 | |
| 98 | public void Run() |
| 99 | { |
| 100 | Process(); |
| 101 | SendEvent(UpdateEventType.ProcessCompleted, true); |
| 102 | } |
| 103 | |
| 104 | public abstract void Process(); |
| 105 | public event EventHandler<UpdateEvent> EventHandler; |
| 106 | } |
| 107 | } |