1using Datalayer.Internal;
3using System.Collections.Generic;
12 private unsafe
void* _nativePtr;
17 private readonly
string _ipcPath;
19 private bool _disposedValue;
20 private bool _isStarted;
22 private readonly List<Client> _clients =
new List<Client>();
23 private readonly List<Provider> _providers =
new List<Provider>();
32 _ipcPath = ipcPath ??
throw new ArgumentNullException(nameof(ipcPath));
34 var ipcPathBuffer = StringBuffer.FromString(_ipcPath);
37 _nativePtr = NativeMethods.Datalayer.DLR_systemCreate(ipcPathBuffer.ToNativePtr());
44 unsafe
void* INative.NativePtr => _nativePtr;
49 internal List<Client> Clients => _clients;
54 internal List<Provider> Providers => _providers;
67 protected virtual void Dispose(
bool disposing)
79 _disposedValue =
true;
99 GC.SuppressFinalize(
this);
105 private void Delete()
109 if (_nativePtr ==
null)
120 NativeMethods.Datalayer.DLR_systemDelete(_nativePtr);
123 _disposedValue =
true;
130 private void DeleteChildren()
133 foreach (var client
in _clients)
140 foreach (var provider
in _providers)
147 if (_factory !=
null)
153 if (_converter !=
null)
161 #region Public Consts
187 #region Public Properties
199 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
216 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
234 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
239 throw new ArgumentNullException(nameof(value));
242 var valueBuffer = StringBuffer.FromString(value);
246 NativeMethods.Datalayer.DLR_systemSetBfbsPath(_nativePtr, valueBuffer.ToNativePtr());
253 #region Public Methods
267 public void Start(
bool startBroker =
false)
271 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
276 NativeMethods.Datalayer.DLR_systemStart(_nativePtr, Convert.ToByte(startBroker));
291 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
299 NativeMethods.Datalayer.DLR_systemStop(_nativePtr, Convert.ToByte(
true));
315 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
318 if (_factory ==
null)
323 throw new InvalidOperationException(
"DatalayerSystem not started");
328 void* factoryPtr = NativeMethods.Datalayer.DLR_systemFactory(_nativePtr);
329 _factory =
new Factory(
this, factoryPtr);
346 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
349 if (_converter ==
null)
353 void* converterPtr = NativeMethods.Datalayer.DLR_systemJsonConverter(_nativePtr);
354 _converter =
new Converter(
this, converterPtr);
Provides the implementation for IDatalayerSystem.
string IpcPath
Gets the path for interprocess communication.
DatalayerSystem(string ipcPath="")
Initializes a new instance of the DatalayerSystem class.
void Stop()
Stops the DatalayerSystem.
static readonly string ProtocolSchemeTcp
Gets the protocol scheme for TCP communication. Recommended to connect to a DatalayerSystem not runni...
static readonly int DefaultProviderPort
Gets the default Provider port.
void Dispose()
Dispose the instance.
string BfbsPath
Sets the binary Flatbuffer path, which contains *.bfbs files.
static readonly int DefaultClientPort
Gets the default Client port.
virtual void Dispose(bool disposing)
Disposes the instance.
bool IsStarted
Gets a value that indicates whether the DatalayerSystem is started.
static readonly string ProtocolSchemeIpc
Gets the protocol scheme for IPC communication. Recommended to connect to a DatalayerSystem running o...
IConverter Converter
Gets the Converter for Variant to JSON conversions.
bool IsDisposed
Gets a value that indicates whether the instance is already disposed and useless.
IFactory Factory
Gets the Factory to create Clients and Providers.
void Start(bool startBroker=false)
Starts the DatalayerSystem.
The IConverter interface.
The IDatalayerSystem interface.