-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from bjrtx/main
Start rewriting Socket.cs
- Loading branch information
Showing
23 changed files
with
251 additions
and
165 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
24 changes: 24 additions & 0 deletions
24
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/AbstractFileObserver.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,24 @@ | ||
using System; | ||
using System.IO; | ||
using UnityEngine; | ||
|
||
namespace VHToolkit.Logging { | ||
abstract class AbstractFileObserver<T> : IObserver<T> { | ||
protected readonly StreamWriter writer; | ||
private IDisposable unsubscriber; | ||
public void OnCompleted() { | ||
unsubscriber.Dispose(); | ||
writer.Dispose(); | ||
} | ||
|
||
public void Subscribe(IObservable<T> observable) => unsubscriber = observable?.Subscribe(this); | ||
|
||
public void OnError(Exception error) => Debug.LogError(error); | ||
|
||
abstract public void OnNext(T value); | ||
|
||
public AbstractFileObserver(string filename) { | ||
writer = new StreamWriter(filename, append: true); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...o-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/AbstractFileObserver.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
34 changes: 34 additions & 0 deletions
34
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Logger.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,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using UnityEngine; | ||
|
||
using VHToolkit.Redirection; | ||
|
||
namespace VHToolkit.Logging { | ||
public partial class Logger<T> : MonoBehaviour, IObservable<T> { | ||
public string logDirectoryPath = "LoggedData\\"; | ||
[SerializeField] protected string optionalFilenamePrefix; | ||
protected readonly int bufferSize = 10; // number of records kept before writing to disk | ||
|
||
protected readonly Queue<T> records = new(); | ||
protected readonly HashSet<IObserver<T>> observers = new(); | ||
protected Interaction script; | ||
|
||
protected void WriteRecords(Queue<T> records) { | ||
if (records.Count > bufferSize) { | ||
foreach (var record in records) { | ||
foreach (var observer in observers) { | ||
observer.OnNext(record); | ||
} | ||
} | ||
records.Clear(); | ||
} | ||
} | ||
|
||
IDisposable IObservable<T>.Subscribe(IObserver<T> observer) { | ||
observers.Add(observer); | ||
return new HashSetUnsubscriber<T>(observers, observer); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Logger.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Unsubscriber.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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace VHToolkit.Logging { | ||
sealed class HashSetUnsubscriber<T> : IDisposable { | ||
private readonly HashSet<IObserver<T>> _observers; | ||
private readonly IObserver<T> _observer; | ||
|
||
public HashSetUnsubscriber(HashSet<IObserver<T>> observers, IObserver<T> observer) { | ||
_observers = observers; | ||
_observer = observer; | ||
} | ||
|
||
public void Dispose() => _observers.Remove(_observer); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Unsubscriber.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 1 addition & 3 deletions
4
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/RedirectionTechnique.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
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
Oops, something went wrong.