public int SignalBuffer(Int32 aBufferID, byte[] aBuffer, Int32 aEventFlags = 0) { var payload = new TByteBuffer(); if (!IsPublished && connection.AutoPublish) Publish(); if (IsPublished) { payload.Prepare(ID); payload.Prepare((Int32) 0); // tick payload.Prepare((Int32) TEventKind.ekBuffer | (aEventFlags & EventFlagsMask)); payload.Prepare(aBufferID); payload.Prepare(aBuffer.Length); payload.Prepare(aBuffer); payload.PrepareApply(); payload.QWrite(ID); payload.QWrite((Int32) (0)); // tick payload.QWrite((Int32) TEventKind.ekBuffer | (aEventFlags & EventFlagsMask)); payload.QWrite(aBufferID); payload.QWrite(aBuffer.Length); payload.QWrite(aBuffer); return connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, payload.Buffer); } else return TConnection.iceNotEventPublished; }
internal void UnPublish(bool aChangeLocalState = true) { if (aChangeLocalState) FIsPublished = false; // send command var payload = new TByteBuffer(); payload.Prepare(EventName); payload.PrepareApply(); payload.QWrite(EventName); connection.WriteCommand(TConnectionPlatform.TCommands.icUnpublish, payload.Buffer); }
// signals (send events) public int SignalEvent(TEventKind aEventKind, byte[] aEventPayload) { var payload = new TByteBuffer(); if (!IsPublished && connection.AutoPublish) Publish(); if (IsPublished) { payload.Prepare(ID); payload.Prepare((Int32) 0); // tick payload.Prepare((Int32) aEventKind); payload.Prepare(aEventPayload); payload.PrepareApply(); payload.QWrite(ID); payload.QWrite((Int32) (0)); // tick payload.QWrite((Int32) aEventKind); payload.QWrite(aEventPayload); return connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, payload.Buffer); } else return TConnection.iceNotEventPublished; }
public int SignalString(string p) { var SmallTestEventPayload = new TByteBuffer(); // build payload for small event SmallTestEventPayload.Prepare(p); SmallTestEventPayload.PrepareApply(); SmallTestEventPayload.QWrite(p); return SignalEvent(TEventKind.ekNormalEvent, SmallTestEventPayload.Buffer); }
private int RequestUniqueClientID() { var payload = new TByteBuffer(); payload.Prepare((Int32) 0); payload.Prepare((Int32) 0); payload.PrepareApply(); payload.QWrite((Int32) 0); payload.QWrite((Int32) 0); return WriteCommand(TCommands.icUniqueClientID, payload.Buffer); }
// timers public int TimerCreate(string aTimerName, Int64 aStartTimeUTCorRelFT, int aResolutionms, double aSpeedFactor, int aRepeatCount = trcInfinite) { var Payload = new TByteBuffer(); if (!IsPublished && connection.AutoPublish) Publish(); if (IsPublished) { Payload.Prepare(ID); Payload.Prepare(aTimerName); Payload.Prepare(aStartTimeUTCorRelFT); Payload.Prepare(aResolutionms); Payload.Prepare(aSpeedFactor); Payload.Prepare(aRepeatCount); Payload.PrepareApply(); Payload.QWrite(ID); Payload.QWrite(aTimerName); Payload.QWrite(aStartTimeUTCorRelFT); Payload.QWrite(aResolutionms); Payload.QWrite(aSpeedFactor); Payload.QWrite(aRepeatCount); return connection.WriteCommand(TConnectionPlatform.TCommands.icCreateTimer, Payload.Buffer); } else return TConnection.iceNotEventPublished; }
public int TimerAcknowledge(string aTimerName, string aClientName, int aProposedTimeStep) { var Payload = new TByteBuffer(); Payload.Prepare(aClientName); Payload.Prepare(aTimerName); Payload.Prepare(aProposedTimeStep); Payload.PrepareApply(); Payload.QWrite(aClientName); Payload.QWrite(aTimerName); Payload.QWrite(aProposedTimeStep); return SignalEvent(TEventKind.ekTimerAcknowledge, Payload.Buffer); }
// status for UpdateStatus public void UpdateStatus(Int32 aProgress, Int32 aStatus) { var payload = new TByteBuffer(); payload.Prepare(aStatus); payload.Prepare(aProgress); payload.PrepareApply(); payload.QWrite(aStatus); payload.QWrite(aProgress); if (FIMB2Compatible) SetVariableValue( UniqueClientID.ToString("X8") + PrefixFederation(OwnerName).ToUpper() + msVarSepChar + ModelStatusVarName, payload); else SetVariableValue(PrefixFederation(OwnerName).ToUpper() + msVarSepChar + ModelStatusVarName, payload, TVarPrefix.vpUniqueClientID); }
public int SignalFocus(double aX, double aY) { if (FFocusEvent == null) FFocusEvent = FindEventAutoPublishL(PrefixFederation(FocusEventName)); if (FFocusEvent != null) { var payload = new TByteBuffer(); payload.Prepare(aX); payload.Prepare(aY); payload.PrepareApply(); payload.QWrite(aX); payload.QWrite(aY); return FFocusEvent.SignalEvent(TEventEntry.TEventKind.ekChangeObjectEvent, payload.Buffer); } else return iceNotEventPublished; }
public void SetVariableValue(string aVarName, string aVarValue) { var payload = new TByteBuffer(); payload.Prepare(aVarName); payload.Prepare(aVarValue); payload.PrepareApply(); payload.QWrite(aVarName); payload.QWrite(aVarValue); WriteCommand(TCommands.icSetVariable, payload.Buffer); }
public void SetVariableValue(string aVarName, TByteBuffer aVarValue, TVarPrefix aVarPrefix) { var payload = new TByteBuffer(); payload.Prepare((Int32) aVarPrefix); payload.Prepare(aVarName); payload.Prepare(aVarValue); payload.PrepareApply(); payload.QWrite((Int32) aVarPrefix); payload.QWrite(aVarName); payload.QWrite(aVarValue); WriteCommand(TCommands.icSetVariablePrefixed, payload.Buffer); }
public void SetState(TConnectionState aState) { var Payload = new TByteBuffer(); Payload.Prepare((Int32) aState); Payload.PrepareApply(); Payload.QWrite((Int32) aState); WriteCommand(TCommands.icSetState, Payload.Buffer); }
public void SetThrottle(Int32 aThrottle) { var Payload = new TByteBuffer(); Payload.Prepare(aThrottle); Payload.PrepareApply(); Payload.QWrite(aThrottle); WriteCommand(TCommands.icSetThrottle, Payload.Buffer); }
private int SetOwner() { if (Connected) { var Payload = new TByteBuffer(); Payload.Prepare(FOwnerID); Payload.Prepare(FOwnerName); Payload.PrepareApply(); Payload.QWrite(FOwnerID); Payload.QWrite(FOwnerName); return WriteCommand(TCommands.icSetClientInfo, Payload.Buffer); } else return iceConnectionClosed; }
public int SignalStream(string aStreamName, Stream aStream) { var payload = new TByteBuffer(); if (!IsPublished && connection.AutoPublish) Publish(); if (IsPublished) { // ekStreamHeader, includes stream name, no stream data var streamNameUtf8 = Encoding.UTF8.GetBytes(aStreamName); var streamID = connection.getConnectionHashCode(streamNameUtf8); payload.Prepare(ID); payload.Prepare((Int32) 0); // tick payload.Prepare((Int32) TEventKind.ekStreamHeader); // event kind payload.Prepare(streamID); payload.Prepare(aStreamName); payload.PrepareApply(); payload.QWrite(ID); payload.QWrite((Int32) 0); // tick var eventKindIndex = payload.WriteCursor; payload.QWrite((Int32) TEventKind.ekStreamHeader); // event kind payload.QWrite(streamID); var bodyIndex = payload.WriteCursor; payload.QWrite(aStreamName); var res = connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, payload.Buffer); if (res > 0) { // ekStreamBody, only buffer size chunks of data // prepare Payload to same value but aStreamName stripped // fixup event kind payload.WriteStart(eventKindIndex); payload.QWrite((Int32) TEventKind.ekStreamBody); payload.WriteStart(bodyIndex); // prepare room for body data payload.PrepareStart(); payload.PrepareSize(TConnection.MaxStreamBodyBuffer); payload.PrepareApply(); // write pointer in ByteBuffer is still at beginning of stream read buffer! // but buffer is already created on correct length Int32 readSize; do { readSize = ReadBytesFromStream(payload, aStream); //ReadSize = aStream.Read(Payload.Buffer, BodyIndex, Connection.MaxStreamBodyBuffer); if (readSize == TConnection.MaxStreamBodyBuffer) res = connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, payload.Buffer); // reset write position payload.WriteStart(bodyIndex); } while ((readSize == TConnection.MaxStreamBodyBuffer) && (res > 0)); if (res > 0) { // clip ByteBuffer to bytes read from stream // write pointer in ByteBuffer is still at beginning of stream read buffer! payload.PrepareStart(); payload.PrepareSize(readSize); payload.PrepareApplyAndTrim(); // fixup event kind payload.WriteStart(eventKindIndex); payload.QWrite((Int32) TEventKind.ekStreamTail); res = connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, payload.Buffer); } } return res; } else return TConnection.iceNotEventPublished; }
public int RequestEventname(string aEventNameFilter, Int32 aEventFilters) { var payload = new TByteBuffer(); payload.Prepare(aEventNameFilter); payload.Prepare(aEventFilters); payload.PrepareApply(); payload.QWrite(aEventNameFilter); payload.QWrite(aEventFilters); return WriteCommand(TCommands.icRequestEventNames, payload.Buffer); }
public int SignalChangeObject(int aAction, int aObjectID, string aAttribute = "") { var Payload = new TByteBuffer(); if (!IsPublished && connection.AutoPublish) Publish(); if (IsPublished) { Payload.Prepare(ID); Payload.Prepare((Int32) 0); // tick Payload.Prepare((Int32) TEventKind.ekChangeObjectEvent); Payload.Prepare(aAction); Payload.Prepare(aObjectID); Payload.Prepare(aAttribute); Payload.PrepareApply(); Payload.QWrite(ID); Payload.QWrite((Int32) (0)); // tick Payload.QWrite((Int32) TEventKind.ekChangeObjectEvent); Payload.QWrite(aAction); Payload.QWrite(aObjectID); Payload.QWrite(aAttribute); return connection.WriteCommand(TConnectionPlatform.TCommands.icEvent, Payload.Buffer); } else return TConnection.iceNotEventPublished; }
public int SignalIntString(string eventName, int cmd, string message) { var smallTestEventPayload = new TByteBuffer(); // build payload for small event smallTestEventPayload.Prepare(cmd); smallTestEventPayload.Prepare(message); smallTestEventPayload.PrepareApply(); smallTestEventPayload.QWrite(cmd); smallTestEventPayload.QWrite(message); return SignalEvent(eventName, TEventEntry.TEventKind.ekNormalEvent, smallTestEventPayload); }
public int TimerSetSpeed(string aTimerName, double aSpeedFactor) { var Payload = new TByteBuffer(); Payload.Prepare(aTimerName); Payload.Prepare(aSpeedFactor); Payload.PrepareApply(); Payload.QWrite(aTimerName); Payload.QWrite(aSpeedFactor); return SignalEvent(TEventKind.ekTimerSetSpeed, Payload.Buffer); }
private int TimerAcknowledgeCmd(TEventKind aEventKind, string aTimerName, string aClientName) { var payload = new TByteBuffer(); payload.Prepare(aTimerName); payload.Prepare(aClientName); payload.PrepareApply(); payload.QWrite(aTimerName); payload.QWrite(aClientName); return SignalEvent(aEventKind, payload.Buffer); }
// log public int LogWriteLn(string aLine, TLogLevel aLevel) { var Payload = new TByteBuffer(); if (!IsPublished && connection.AutoPublish) Publish(); if (IsPublished) { Payload.Prepare((Int32) 0); // client id filled in by hub Payload.Prepare(aLine); Payload.Prepare((Int32) aLevel); Payload.PrepareApply(); Payload.QWrite((Int32) 0); // client id filled in by hub Payload.QWrite(aLine); Payload.QWrite((Int32) aLevel); return SignalEvent(TEventKind.ekLogWriteLn, Payload.Buffer); } else return TConnection.iceNotEventPublished; }
internal void Publish() { FIsPublished = true; // send command var payload = new TByteBuffer(); payload.Prepare(ID); payload.Prepare(0); // EET payload.Prepare(EventName); payload.PrepareApply(); payload.QWrite(ID); payload.QWrite(0); // EET payload.QWrite(EventName); connection.WriteCommand(TConnectionPlatform.TCommands.icPublish, payload.Buffer); }
private void SignalEvent(int commandId, string body = null) { if (_effectsEvent == null) { ImbSubscribe(); if (_effectsEvent == null) return; } Debug.WriteLine(string.Format("Send IMB command {0}:\n{1}", commandId, body)); TByteBuffer Payload = new TByteBuffer(); Payload.Prepare((int)commandId); if (body != null) { Payload.Prepare(body); } Payload.PrepareApply(); Payload.QWrite((int)commandId); if (body != null) { Payload.QWrite(body); } _effectsEvent.SignalEvent(TEventEntry.TEventKind.ekNormalEvent, Payload.Buffer); }
internal int WriteCommand(TCommands aCommand, byte[] aPayload) { lock (WriteCommandLock) { var Buffer = new TByteBuffer(); Buffer.Prepare(MagicBytes); Buffer.Prepare((Int32) aCommand); Buffer.Prepare((Int32) 0); // payload size if ((aPayload != null) && (aPayload.Length > 0)) { Buffer.Prepare(aPayload); Buffer.Prepare(CheckStringMagic); } Buffer.PrepareApply(); Buffer.QWrite(MagicBytes); Buffer.QWrite((Int32) aCommand); if ((aPayload != null) && (aPayload.Length > 0)) { Buffer.QWrite((Int32) aPayload.Length); Buffer.QWrite(aPayload); Buffer.QWrite(CheckStringMagic); } else Buffer.QWrite((Int32) 0); // send buffer over socket if (Connected) { try { WriteCommandLow(Buffer.Buffer, Buffer.Length); return Buffer.Length; } catch { Close(); return iceConnectionClosed; } } else return iceConnectionClosed; } }