|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.IO; |
|
19 using System.Collections.Generic; |
|
20 using System.Text; |
|
21 using System.Threading; |
|
22 using SymbianUtils; |
|
23 using SymbianUtils.PluginManager; |
|
24 using SymbianUtils.FileSystem; |
|
25 using SymbianUtils.Settings; |
|
26 using SymbianDebugLib.Engine; |
|
27 using SymbianDebugLib.PluginAPI; |
|
28 |
|
29 namespace SymbianDebugLib.Entity.Primer |
|
30 { |
|
31 internal class DbgEntityPrimerSilent : IDbgEntityPrimer |
|
32 { |
|
33 #region Constructors |
|
34 public DbgEntityPrimerSilent( DbgEntity aEntity, DbgPluginEngine aPlugin ) |
|
35 { |
|
36 iEntity = aEntity; |
|
37 iPlugin = aPlugin; |
|
38 |
|
39 // Make a new primer and seed it with the entity. |
|
40 iPrimer = aPlugin.CreatePrimer(); |
|
41 iPrimer.Add( aEntity ); |
|
42 |
|
43 // Listen to plugin primer events |
|
44 iPrimer.EventHandler += new DbgPluginPrimer.PrimeEventHandler( PrimerPlugin_EventHandler ); |
|
45 } |
|
46 #endregion |
|
47 |
|
48 #region From IDbgEntityPrimer |
|
49 public void Prime( TSynchronicity aSynchronicity ) |
|
50 { |
|
51 PrimeException = null; |
|
52 // |
|
53 try |
|
54 { |
|
55 iPrimer.Prime( aSynchronicity ); |
|
56 } |
|
57 catch ( Exception e ) |
|
58 { |
|
59 OnPrimeStart(); |
|
60 PrimeException = e; |
|
61 OnPrimeComplete(); |
|
62 } |
|
63 } |
|
64 |
|
65 public string PrimeErrorMessage |
|
66 { |
|
67 get { return iEntity.PrimerResult.PrimeErrorMessage; } |
|
68 } |
|
69 |
|
70 public Exception PrimeException |
|
71 { |
|
72 get { return iEntity.PrimerResult.PrimeException; } |
|
73 internal set { iEntity.PrimerResult.PrimeException = value; } |
|
74 } |
|
75 #endregion |
|
76 |
|
77 #region Properties |
|
78 public bool PrimedOkay |
|
79 { |
|
80 get { return iEntity.PrimerResult.PrimedOkay; } |
|
81 } |
|
82 |
|
83 public DbgEntity Entity |
|
84 { |
|
85 get { return iEntity; } |
|
86 } |
|
87 |
|
88 public DbgPluginEngine Plugin |
|
89 { |
|
90 get { return iPlugin; } |
|
91 } |
|
92 #endregion |
|
93 |
|
94 #region Event handlers |
|
95 private void PrimerPlugin_EventHandler( DbgPluginPrimer.TPrimeEvent aEvent, object aData ) |
|
96 { |
|
97 switch ( aEvent ) |
|
98 { |
|
99 case DbgPluginPrimer.TPrimeEvent.EEventPrimingStarted: |
|
100 OnPrimeStart(); |
|
101 break; |
|
102 case DbgPluginPrimer.TPrimeEvent.EEventPrimingProgress: |
|
103 if ( aData != null && ( aData is int ) ) |
|
104 { |
|
105 int prog = (int) aData; |
|
106 OnPrimeProgress( prog ); |
|
107 } |
|
108 break; |
|
109 case DbgPluginPrimer.TPrimeEvent.EEventPrimingComplete: |
|
110 OnPrimeComplete(); |
|
111 break; |
|
112 } |
|
113 } |
|
114 #endregion |
|
115 |
|
116 #region Event cascading |
|
117 protected void OnPrimeStart() |
|
118 { |
|
119 bool sent = ( ( iFlags & TFlags.EFlagsSentEventStart ) == TFlags.EFlagsSentEventStart ); |
|
120 if ( !sent ) |
|
121 { |
|
122 iEntity.OnPrimeStart( this ); |
|
123 iFlags |= TFlags.EFlagsSentEventStart; |
|
124 } |
|
125 } |
|
126 |
|
127 protected void OnPrimeProgress( int aValue ) |
|
128 { |
|
129 iEntity.OnPrimeProgress( this, aValue ); |
|
130 } |
|
131 |
|
132 protected void OnPrimeComplete() |
|
133 { |
|
134 bool sent = ( ( iFlags & TFlags.EFlagsSentEventComplete ) == TFlags.EFlagsSentEventComplete ); |
|
135 if ( !sent ) |
|
136 { |
|
137 // Update entity's primer results |
|
138 iEntity.OnPrimeComplete( this ); |
|
139 iFlags |= TFlags.EFlagsSentEventComplete; |
|
140 } |
|
141 } |
|
142 #endregion |
|
143 |
|
144 #region Internal methods |
|
145 #endregion |
|
146 |
|
147 #region Internal enumerations |
|
148 [Flags] |
|
149 private enum TFlags |
|
150 { |
|
151 EFlagsNone = 0, |
|
152 EFlagsSentEventStart = 1, |
|
153 EFlagsSentEventComplete = 2 |
|
154 } |
|
155 #endregion |
|
156 |
|
157 #region Data members |
|
158 private readonly DbgEntity iEntity; |
|
159 private readonly DbgPluginEngine iPlugin; |
|
160 private readonly DbgPluginPrimer iPrimer; |
|
161 private TFlags iFlags = TFlags.EFlagsNone; |
|
162 #endregion |
|
163 } |
|
164 } |