-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
0743675
commit b74c164
Showing
6 changed files
with
164 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
source/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/EngineState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// Copyright (c) 2017 The nanoFramework project contributors | ||
// Portions Copyright (c) Microsoft Corporation. All rights reserved. | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
|
||
namespace nanoFramework.Tools.Debugger | ||
{ | ||
internal class EngineState | ||
{ | ||
public enum Value | ||
{ | ||
NotStarted, | ||
Starting, | ||
Started, | ||
Stopping, | ||
Resume, | ||
Stopped, | ||
Disposing, | ||
Disposed | ||
} | ||
|
||
private Value _value; | ||
public object SyncObject { get; private set; } | ||
|
||
public EngineState(object syncObject) | ||
{ | ||
_value = Value.NotStarted; | ||
SyncObject = syncObject; | ||
} | ||
|
||
public Value GetValue() | ||
{ | ||
return _value; | ||
} | ||
|
||
public bool SetValue(Value value) | ||
{ | ||
return SetValue(value, false); | ||
} | ||
|
||
public bool SetValue(Value value, bool fThrow) | ||
{ | ||
lock (SyncObject) | ||
{ | ||
if (_value == Value.Stopping && value == Value.Resume) | ||
{ | ||
_value = Value.Started; | ||
return true; | ||
} | ||
else if (_value < value) | ||
{ | ||
_value = value; | ||
return true; | ||
} | ||
else | ||
{ | ||
if (fThrow) | ||
{ | ||
throw new Exception(string.Format("Cannot set State to {0}", value)); | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
|
||
public bool IsRunning | ||
{ | ||
get | ||
{ | ||
Value val = _value; | ||
|
||
return val == Value.Starting || val == Value.Started; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters