1 package nl.tno.imb;
2
3 import nl.tno.imb.TConnection;
4
5 import java.io.InputStream;
6 import java.io.OutputStream;
7 import java.util.ArrayList;
8 import java.util.List;
9 import java.io.IOException;
10 import java.nio.charset.Charset;
11
12
13
14
15
16
17
18 public class TEventEntry {
19
20 TEventEntry(TConnection aConnection, int aID, String aEventName) {
21 this.connection = aConnection;
22 this.ID = aID;
23 this.feventName = aEventName;
24 this.fparent = null;
25 this.fisPublished = false;
26 this.fisSubscribed = false;
27 }
28
29 static final int IC_INVALID_COMMAND = -1;
30
31 static final int IC_END_OF_SESSION = -5;
32
33 static final int IC_UNIQUE_CLIENT_ID = -7;
34
35
36 static final int IC_EVENT = -15;
37
38
39
40
41
42 static final int IC_SET_CLIENT_INFO = -31;
43 static final int IC_SET_VARIABLE = -32;
44 static final int IC_ALL_VARIABLES = -33;
45 static final int IC_SET_STATE = -34;
46 static final int IC_SET_THROTTLE = -35;
47
48 static final int IC_SET_VARIABLE_PREFIXED = -37;
49
50 static final int IC_REQUEST_EVENT_NAMES = -41;
51 static final int IC_EVENT_NAMES = -42;
52
53
54
55 static final int IC_SUBSCRIBE = -45;
56 static final int IC_UNSUBSCRIBE = -46;
57 static final int IC_PUBLISH = -47;
58 static final int IC_UNPUBLISH = -48;
59
60 static final int IC_SET_EVENT_ID_TRANSLATION = -49;
61
62
63
64
65
66
67
68
69
70
71
72
73 static final int IC_CREATE_TIMER = -73;
74
75
76 static final int IC_HUB_LOCATE = -81;
77 static final int IC_HUB_FOUND = -82;
78
79
80
81
82
83
84
85
86
87 public static final int EK_CHANGE_OBJECT_EVENT = 0;
88
89
90 public static final int EK_STREAM_HEADER = 1;
91
92 public static final int EK_STREAM_BODY = 2;
93
94 public static final int EK_STREAM_TAIL = 3;
95
96 public static final int EK_BUFFER = 4;
97
98 public static final int EK_NORMAL_EVENT = 5;
99
100
101 public static final int EK_CHANGE_OBJECT_DATA_EVENT = 6;
102
103 public static final int EK_CHILD_EVENT_ADD = 11;
104
105 public static final int EK_CHILD_EVENT_REMOVE = 12;
106
107 public static final int EK_LOG_WRITELN = 30;
108
109 public static final int EK_TIMER_CANCEL = 40;
110
111 public static final int EK_TIMER_PREPARE = 41;
112
113 public static final int EK_TIMER_START = 42;
114
115 public static final int EK_TIMER_STOP = 43;
116
117 public static final int EK_TIMER_ACKNOWLEDGE_LIST_ADD = 45;
118
119 public static final int EK_TIMER_ACKNOWLEDGE_LIST_REMOVE = 46;
120
121 public static final int EK_TIMER_SET_SPEED = 47;
122
123 public static final int EK_TIMER_TICK = 48;
124
125 public static final int EK_TIMER_ACKNOWLEDGE = 49;
126
127 public static final int EK_TIMER_STATUS_REQUEST = 50;
128
129
130 public enum TLogLevel {
131 llRemark,
132 llDump,
133 llNormal,
134 llStart,
135 llFinish,
136 llPush,
137 llPop,
138 llStamp,
139 llSummary,
140 llWarning,
141 llError
142 }
143
144
145 public static final int TRC_INFINITE = Integer.MAX_VALUE;
146
147 private static final int MAX_STREAM_BODY_BUFFER_SIZE = 16 * 1024;
148
149
150 private static final int EVENT_KIND_MASK = 0x000000FF;
151 private static final int EVENT_FLAGS_MASK = 0x0000FF00;
152
153 private class TStreamCacheEntry {
154 private int fstreamID;
155 private OutputStream fstream;
156 private String fname;
157
158 public TStreamCacheEntry(int aStreamID, OutputStream aStream, String aStreamName) {
159 this.fstreamID = aStreamID;
160 this.fstream = aStream;
161 this.fname = aStreamName;
162 }
163 }
164
165 private class TStreamCache {
166 private List<TStreamCacheEntry> fstreamCacheList = new ArrayList<TStreamCacheEntry>();
167
168 public TStreamCacheEntry find(int aStreamID) {
169 for (int i = 0; i < this.fstreamCacheList.size(); i++) {
170 TStreamCacheEntry sce = this.fstreamCacheList.get(i);
171 if (sce.fstreamID == aStreamID)
172 return sce;
173 }
174 return null;
175 }
176
177 public void cache(int aStreamID, OutputStream aStream, String aStreamName) {
178 this.fstreamCacheList.add(new TStreamCacheEntry(aStreamID, aStream, aStreamName));
179 }
180
181 public void remove(int aStreamID) {
182 int i = 0;
183 while ((i < this.fstreamCacheList.size()) && (this.fstreamCacheList.get(i).fstreamID != aStreamID))
184 i++;
185 if (i < this.fstreamCacheList.size())
186 this.fstreamCacheList.remove(i);
187 }
188 }
189
190 private boolean fisPublished;
191 private boolean fisSubscribed;
192 String feventName;
193 TEventEntry fparent;
194 private TStreamCache fstreamCache = new TStreamCache();
195
196 private int timerBasicCmd(int aEventKind, String aTimerName) {
197 TByteBuffer Payload = new TByteBuffer();
198 Payload.prepare(aTimerName);
199 Payload.prepareApply();
200 Payload.qWrite(aTimerName);
201 return signalEvent(aEventKind, Payload.getBuffer());
202 }
203
204 private int timerAcknowledgeCmd(int aEventKind, String aTimerName, String aClientName) {
205 TByteBuffer Payload = new TByteBuffer();
206 Payload.prepare(aTimerName);
207 Payload.prepare(aClientName);
208 Payload.prepareApply();
209 Payload.qWrite(aTimerName);
210 Payload.qWrite(aClientName);
211 return signalEvent(aEventKind, Payload.getBuffer());
212 }
213
214 void subscribe() {
215 this.fisSubscribed = true;
216
217 TByteBuffer Payload = new TByteBuffer();
218 Payload.prepare(this.ID);
219 Payload.prepare(0);
220 Payload.prepare(getEventName());
221 Payload.prepareApply();
222 Payload.qWrite(this.ID);
223 Payload.qWrite(0);
224 Payload.qWrite(getEventName());
225 this.connection.writeCommand(IC_SUBSCRIBE, Payload.getBuffer());
226 }
227
228 void publish() {
229 this.fisPublished = true;
230
231 TByteBuffer Payload = new TByteBuffer();
232 Payload.prepare(this.ID);
233 Payload.prepare(0);
234 Payload.prepare(getEventName());
235 Payload.prepareApply();
236 Payload.qWrite(this.ID);
237 Payload.qWrite(0);
238 Payload.qWrite(getEventName());
239 this.connection.writeCommand(IC_PUBLISH, Payload.getBuffer());
240 }
241
242 boolean isEmpty() {
243 return !(this.fisSubscribed || this.fisPublished);
244 }
245
246 private boolean fSubscribers;
247 private boolean fPublishers;
248 public boolean subscribers() { return this.fSubscribers; }
249 public boolean publishers() { return this.fPublishers; }
250
251 void unSubscribe(boolean aChangeLocalState)
252 {
253 if (aChangeLocalState)
254 this.fisSubscribed = false;
255
256 TByteBuffer Payload = new TByteBuffer();
257 Payload.prepare(getEventName());
258 Payload.prepareApply();
259 Payload.qWrite(getEventName());
260 this.connection.writeCommand(IC_UNSUBSCRIBE, Payload.getBuffer());
261 }
262
263 void unPublish(boolean aChangeLocalState)
264 {
265 if (aChangeLocalState)
266 this.fisPublished = false;
267
268 TByteBuffer Payload = new TByteBuffer();
269 Payload.prepare(getEventName());
270 Payload.prepareApply();
271 Payload.qWrite(getEventName());
272 this.connection.writeCommand(IC_UNPUBLISH, Payload.getBuffer());
273 }
274
275
276 void handleEvent(TByteBuffer aPayload)
277 {
278 int EventTick;
279 int EventKindInt;
280 EventTick = aPayload.readInt32();
281 EventKindInt = aPayload.readInt32();
282 int eventKind = EventKindInt & EVENT_KIND_MASK;
283 switch (eventKind) {
284 case EK_CHANGE_OBJECT_EVENT:
285 handleChangeObject(aPayload);
286 break;
287 case EK_CHANGE_OBJECT_DATA_EVENT:
288 handleChangeObjectData(aPayload);
289 break;
290 case EK_BUFFER:
291 handleBuffer(EventTick, aPayload);
292 break;
293 case EK_NORMAL_EVENT:
294 if (this.onNormalEvent != null)
295 this.onNormalEvent.dispatch(this, aPayload);
296 break;
297 case EK_TIMER_TICK:
298 handleTimerTick(aPayload);
299 break;
300 case EK_TIMER_PREPARE:
301 handleTimerCmd(EK_TIMER_PREPARE, aPayload);
302 break;
303 case EK_TIMER_START:
304 handleTimerCmd(EK_TIMER_START, aPayload);
305 break;
306 case EK_TIMER_STOP:
307 handleTimerCmd(EK_TIMER_STOP, aPayload);
308 break;
309 case EK_STREAM_HEADER:
310 handleStreamEvent(EK_STREAM_HEADER, aPayload);
311 break;
312 case EK_STREAM_BODY:
313 handleStreamEvent(EK_STREAM_BODY, aPayload);
314 break;
315 case EK_STREAM_TAIL:
316 handleStreamEvent(EK_STREAM_TAIL, aPayload);
317 break;
318 case EK_CHILD_EVENT_ADD:
319 handleChildEvent(EK_CHILD_EVENT_ADD, aPayload);
320 break;
321 case EK_CHILD_EVENT_REMOVE:
322 handleChildEvent(EK_CHILD_EVENT_REMOVE, aPayload);
323 break;
324 default:
325 if (this.onOtherEvent != null)
326 this.onOtherEvent.dispatch(this, EventTick, eventKind, aPayload);
327 break;
328 }
329
330 }
331
332
333 private void handleChangeObject(TByteBuffer aPayload) {
334 if (this.onFocus != null) {
335 double X;
336 double Y;
337 X = aPayload.readDouble();
338 Y = aPayload.readDouble();
339 this.onFocus.dispatch(X, Y);
340 } else {
341 if (this.onChangeFederation != null) {
342 aPayload.readInt32();
343 int NewFederationID = aPayload.readInt32();
344 String NewFederation = aPayload.readString();
345 this.onChangeFederation.dispatch(this.connection, NewFederationID, NewFederation);
346 } else {
347 if (this.onChangeObject != null) {
348 int Action = aPayload.readInt32();
349 int ObjectID = aPayload.readInt32();
350 String Attribute = aPayload.readString();
351 this.onChangeObject.dispatch(Action, ObjectID, getShortEventName(), Attribute);
352 }
353 }
354 }
355 }
356
357 private void handleChangeObjectData(TByteBuffer aPayload) {
358 if (this.onChangeObjectData != null) {
359 int Action = aPayload.readInt32();
360 int ObjectID = aPayload.readInt32();
361 String Attribute = aPayload.readString();
362 TByteBuffer NewValues = aPayload.readByteBuffer();
363 TByteBuffer OldValues = aPayload.readByteBuffer();
364 this.onChangeObjectData.dispatch(this, Action, ObjectID, Attribute, NewValues, OldValues);
365 }
366 }
367
368 private void handleBuffer(int aEventTick, TByteBuffer aPayload) {
369 if (this.onBuffer != null) {
370 int BufferID = aPayload.readInt32();
371 TByteBuffer Buffer = aPayload.readByteBuffer();
372 this.onBuffer.dispatch(this, aEventTick, BufferID, Buffer);
373 }
374 }
375
376 private void handleTimerTick(TByteBuffer aPayload) {
377 if (this.onTimerTick != null) {
378 String TimerName = aPayload.readString();
379 int Tick = aPayload.readInt32();
380 long TickTime = aPayload.readInt64();
381 long StartTime = aPayload.readInt64();
382 this.onTimerTick.dispatch(this, TimerName, Tick, TickTime, StartTime);
383 }
384 }
385
386 private void handleTimerCmd(int aEventKind, TByteBuffer aPayload) {
387 if (this.onTimerCmd != null) {
388 String TimerName = aPayload.readString();
389 this.onTimerCmd.dispatch(this, aEventKind, TimerName);
390 }
391 }
392
393 private void handleChildEvent(int aEventKind, TByteBuffer aPayload) {
394 if (this.onChildEvent != null) {
395 String EventName = aPayload.readString();
396 this.onChildEvent.dispatch(this, aEventKind, EventName);
397 }
398 }
399
400 private void handleStreamEvent(int aEventKind, TByteBuffer aPayload) {
401 int StreamID;
402 String StreamName;
403 OutputStream stream;
404 TStreamCacheEntry sce;
405 switch (aEventKind) {
406 case EK_STREAM_HEADER:
407 if (this.onStreamCreate != null) {
408 StreamID = aPayload.readInt32();
409 StreamName = aPayload.readString();
410 stream = this.onStreamCreate.dispatch(this, StreamName);
411 if (stream != null)
412 this.fstreamCache.cache(StreamID, stream, StreamName);
413 }
414 break;
415 case EK_STREAM_BODY:
416 StreamID = aPayload.readInt32();
417 sce = this.fstreamCache.find(StreamID);
418 if ((sce != null) && (sce.fstream != null)) {
419 try {
420 sce.fstream.write(aPayload.getBuffer(), aPayload.getReadCursor(), aPayload.getReadAvailable());
421 } catch (IOException e) {
422
423 e.printStackTrace();
424 }
425 }
426 break;
427 case EK_STREAM_TAIL:
428 StreamID = aPayload.readInt32();
429 sce = this.fstreamCache.find(StreamID);
430 if ((sce != null) && (sce.fstream != null)) {
431 try {
432 sce.fstream.write(aPayload.getBuffer(), aPayload.getReadCursor(), aPayload.getReadAvailable());
433 if (this.onStreamEnd != null)
434 this.onStreamEnd.dispatch(this, sce.fstream, sce.fname);
435 sce.fstream.close();
436 } catch (IOException e) {
437
438 e.printStackTrace();
439 }
440 this.fstreamCache.remove(StreamID);
441 }
442 break;
443 }
444 }
445
446 void handleSubAndPub(int aCommand) {
447 if (this.fparent == null && this.onSubAndPub != null)
448 this.onSubAndPub.dispatch(this, aCommand);
449 switch (aCommand)
450 {
451 case IC_SUBSCRIBE:
452 if (this.fparent != null && !isPublished())
453 publish();
454 this.fSubscribers = true;
455 break;
456 case IC_PUBLISH:
457 if (this.fparent != null && !isSubscribed())
458 subscribe();
459 this.fPublishers = true;
460 break;
461 case IC_UNSUBSCRIBE:
462 if (this.fparent != null && isPublished())
463 unPublish(true);
464 this.fSubscribers = false;
465 break;
466 case IC_UNPUBLISH:
467 if (this.fparent != null && isSubscribed())
468 unSubscribe(true);
469 this.fPublishers = false;
470 break;
471 }
472 }
473
474
475
476 private final TConnection connection;
477
478
479 public final int ID;
480
481
482 public String getEventName() {
483 return this.feventName;
484 }
485
486 public String getShortEventName() {
487 String federationPrefix = this.connection.getFederation()+".";
488 if (this.feventName.startsWith(federationPrefix))
489 return this.feventName.substring(federationPrefix.length());
490 else
491 return this.feventName;
492 }
493
494
495 public boolean isPublished() {
496 return this.fisPublished;
497 }
498
499
500 public boolean isSubscribed() {
501 return this.fisSubscribed;
502 }
503
504 public void copyHandlersFrom(TEventEntry aEventEntry) {
505 this.onChangeObject = aEventEntry.onChangeObject;
506 this.onFocus = aEventEntry.onFocus;
507 this.onNormalEvent = aEventEntry.onNormalEvent;
508 this.onBuffer = aEventEntry.onBuffer;
509 this.onStreamCreate = aEventEntry.onStreamCreate;
510 this.onStreamEnd = aEventEntry.onStreamEnd;
511 this.onChangeFederation = aEventEntry.onChangeFederation;
512 this.onTimerTick = aEventEntry.onTimerTick;
513 this.onTimerCmd = aEventEntry.onTimerCmd;
514 this.onChangeObjectData = aEventEntry.onChangeObjectData;
515 this.onOtherEvent = aEventEntry.onOtherEvent;
516 this.onSubAndPub = aEventEntry.onSubAndPub;
517 }
518
519
520
521 public interface TOnChangeObject {
522 void dispatch(int aAction, int aObjectID, String aObjectName, String aAttribute);
523 }
524
525
526 public TOnChangeObject onChangeObject = null;
527
528
529 public interface TOnFocus {
530 public void dispatch(double x, double y);
531 }
532
533
534 public TOnFocus onFocus = null;
535
536
537
538 public interface TOnNormalEvent {
539 public void dispatch(TEventEntry aEvent, TByteBuffer aPayload);
540 }
541
542
543 public TOnNormalEvent onNormalEvent = null;
544
545
546 public interface TOnBuffer {
547 public void dispatch(TEventEntry aEvent, int aTick, int aBufferID, TByteBuffer aBuffer);
548 }
549
550
551 public TOnBuffer onBuffer = null;
552
553
554 public interface TOnStreamCreate {
555 public OutputStream dispatch(TEventEntry aEvent, String aStreamName);
556 }
557
558
559 public TOnStreamCreate onStreamCreate = null;
560
561
562 public interface TOnStreamEnd {
563 public void dispatch(TEventEntry aEvent, OutputStream aStream, String aStreamName);
564 }
565
566
567 public TOnStreamEnd onStreamEnd = null;
568
569
570 public interface TOnChangeFederation {
571 public void dispatch(TConnection aConnection, int aNewFederationID, String aNewFederation);
572 }
573
574
575 public TOnChangeFederation onChangeFederation = null;
576
577
578
579 public interface TOnTimerTick {
580 public void dispatch(TEventEntry aEvent, String aTimerName, int aTick, long aTickTime, long aStartTime);
581 }
582
583
584 public TOnTimerTick onTimerTick = null;
585
586
587 public interface TOnTimerCmd {
588 public void dispatch(TEventEntry aEvent, int aEventKind, String aTimerName);
589 }
590
591
592 public TOnTimerCmd onTimerCmd = null;
593
594
595 public interface TOnChildEvent {
596 public void dispatch(TEventEntry aEvent, int aEventKind, String aEventName);
597 }
598
599
600 public TOnChildEvent onChildEvent = null;
601
602
603 public interface TOnChangeObjectData {
604 public void dispatch(TEventEntry aEvent, int aAction, int aObjectID, String aAttribute, TByteBuffer aNewValues, TByteBuffer aOldValues);
605 }
606
607
608 public TOnChangeObjectData onChangeObjectData = null;
609
610
611 public interface TOnSubAndPubEvent {
612 public void dispatch(TEventEntry aEvent, int aCommand);
613 }
614
615
616 public TOnSubAndPubEvent onSubAndPub = null;
617
618
619 public interface TOnOtherEvent {
620 public void dispatch(TEventEntry aEvent, int aTick, int aEventKind, TByteBuffer aPayload);
621 }
622
623
624 public TOnOtherEvent onOtherEvent = null;
625
626
627
628
629
630
631
632
633 public int signalEvent(int aEventKind, byte[] aEventPayload) {
634 TByteBuffer Payload = new TByteBuffer();
635 if (!isPublished() && this.connection.autoPublish)
636 publish();
637 if (isPublished()) {
638 Payload.prepare(this.ID);
639 Payload.prepare((int) 0);
640 Payload.prepare(aEventKind);
641 Payload.prepare(aEventPayload);
642 Payload.prepareApply();
643 Payload.qWrite(this.ID);
644 Payload.qWrite((int) (0));
645 Payload.qWrite(aEventKind);
646 Payload.qWrite(aEventPayload);
647 return this.connection.writeCommand(IC_EVENT, Payload.getBuffer());
648 } else
649 return TConnection.ICE_EVENT_NOT_PUBLISHED;
650 }
651
652
653
654
655
656
657 public int signalBuffer(int aBufferID, byte[] aBuffer) {
658 return signalBuffer(aBufferID, aBuffer, 0);
659 }
660
661
662
663
664
665
666
667 public int signalBuffer(int aBufferID, byte[] aBuffer, int aEventFlags) {
668 TByteBuffer Payload = new TByteBuffer();
669 if (!isPublished() && this.connection.autoPublish)
670 publish();
671 if (isPublished()) {
672 Payload.prepare(this.ID);
673 Payload.prepare((int) 0);
674 Payload.prepare(EK_BUFFER | (aEventFlags & EVENT_FLAGS_MASK));
675 Payload.prepare(aBufferID);
676 Payload.prepare(aBuffer.length);
677 Payload.prepare(aBuffer);
678 Payload.prepareApply();
679 Payload.qWrite(this.ID);
680 Payload.qWrite((int) (0));
681 Payload.qWrite(EK_BUFFER | (aEventFlags & EVENT_FLAGS_MASK));
682 Payload.qWrite(aBufferID);
683 Payload.qWrite(aBuffer.length);
684 Payload.qWrite(aBuffer);
685 return this.connection.writeCommand(IC_EVENT, Payload.getBuffer());
686 } else
687 return TConnection.ICE_EVENT_NOT_PUBLISHED;
688 }
689
690 private int readBytesFromStream(TByteBuffer aBuffer, InputStream aStream) {
691 try {
692
693 int Count = 0;
694 int NumBytesRead = 1;
695 while (aBuffer.getwriteAvailable() > 0 && NumBytesRead > 0) {
696 NumBytesRead = aStream.read(aBuffer.getBuffer(), aBuffer.getWriteCursor(), aBuffer.getwriteAvailable());
697 if (NumBytesRead > 0)
698 {
699 aBuffer.written(NumBytesRead);
700 Count += NumBytesRead;
701 }
702 }
703 return Count;
704 } catch (IOException ex) {
705 return 0;
706 }
707 }
708
709
710
711
712
713
714 public int signalStream(String aStreamName, InputStream aStream) {
715 TByteBuffer Payload = new TByteBuffer();
716 int ReadSize;
717 int BodyIndex;
718 int EventKindIndex;
719 if (!isPublished() && this.connection.autoPublish)
720 publish();
721 if (isPublished()) {
722
723 byte[] StreamNameUTF8 = aStreamName.getBytes(Charset.forName("UTF-8"));
724
725 int StreamID = StreamNameUTF8.hashCode() + this.connection.hashCode();
726 Payload.prepare(this.ID);
727 Payload.prepare((int) 0);
728 Payload.prepare(EK_STREAM_HEADER);
729 Payload.prepare(StreamID);
730 Payload.prepare(aStreamName);
731 Payload.prepareApply();
732 Payload.qWrite(this.ID);
733 Payload.qWrite((int) 0);
734 EventKindIndex = Payload.getWriteCursor();
735 Payload.qWrite(EK_STREAM_HEADER);
736 Payload.qWrite(StreamID);
737 BodyIndex = Payload.getWriteCursor();
738 Payload.qWrite(aStreamName);
739 int res = this.connection.writeCommand(IC_EVENT, Payload.getBuffer());
740 if (res > 0) {
741
742
743
744 Payload.writeStart(EventKindIndex);
745 Payload.qWrite(EK_STREAM_BODY);
746 Payload.writeStart(BodyIndex);
747
748 Payload.prepareStart();
749 Payload.prepareSize(MAX_STREAM_BODY_BUFFER_SIZE);
750 Payload.prepareApply();
751
752
753 do {
754 ReadSize = readBytesFromStream(Payload, aStream);
755
756 if (ReadSize == MAX_STREAM_BODY_BUFFER_SIZE)
757 res = this.connection.writeCommand(IC_EVENT, Payload.getBuffer());
758
759 Payload.writeStart(BodyIndex);
760 } while ((ReadSize == MAX_STREAM_BODY_BUFFER_SIZE) && (res > 0));
761 if (res > 0) {
762
763
764 Payload.prepareStart();
765 Payload.prepareSize(ReadSize);
766 Payload.prepareApplyAndTrim();
767
768 Payload.writeStart(EventKindIndex);
769 Payload.qWrite(EK_STREAM_TAIL);
770 res = this.connection.writeCommand(IC_EVENT, Payload.getBuffer());
771 }
772 }
773 return res;
774 } else
775 return TConnection.ICE_EVENT_NOT_PUBLISHED;
776 }
777
778
779 public static final int ACTION_NEW = 0;
780
781 public static final int ACTION_DELETE = 1;
782
783 public static final int ACTION_CHANGE = 2;
784
785
786
787
788
789
790
791 public int signalChangeObject(int aAction, int aObjectID, String aAttribute) {
792 TByteBuffer Payload = new TByteBuffer();
793 if (!isPublished() && this.connection.autoPublish)
794 publish();
795 if (isPublished()) {
796 Payload.prepare(this.ID);
797 Payload.prepare((int) 0);
798 Payload.prepare(EK_CHANGE_OBJECT_EVENT);
799 Payload.prepare(aAction);
800 Payload.prepare(aObjectID);
801 Payload.prepare(aAttribute);
802 Payload.prepareApply();
803 Payload.qWrite(this.ID);
804 Payload.qWrite((int) (0));
805 Payload.qWrite(EK_CHANGE_OBJECT_EVENT);
806 Payload.qWrite(aAction);
807 Payload.qWrite(aObjectID);
808 Payload.qWrite(aAttribute);
809 return this.connection.writeCommand(IC_EVENT, Payload.getBuffer());
810 } else
811 return TConnection.ICE_EVENT_NOT_PUBLISHED;
812 }
813
814
815
816
817
818
819
820
821
822 public int timerCreate(String aTimerName, long aStartTimeUTCorRelFT, int aResolutionms, double aSpeedFactor) {
823 return timerCreate(aTimerName, aStartTimeUTCorRelFT, aResolutionms, aSpeedFactor, TRC_INFINITE);
824 }
825
826
827
828
829
830
831
832
833
834 public int timerCreate(String aTimerName, long aStartTimeUTCorRelFT, int aResolutionms, double aSpeedFactor,
835 int aRepeatCount) {
836 TByteBuffer Payload = new TByteBuffer();
837 if (!isPublished() && this.connection.autoPublish)
838 publish();
839 if (isPublished()) {
840 Payload.prepare(this.ID);
841 Payload.prepare(aTimerName);
842 Payload.prepare(aStartTimeUTCorRelFT);
843 Payload.prepare(aResolutionms);
844 Payload.prepare(aSpeedFactor);
845 Payload.prepare(aRepeatCount);
846 Payload.prepareApply();
847 Payload.qWrite(this.ID);
848 Payload.qWrite(aTimerName);
849 Payload.qWrite(aStartTimeUTCorRelFT);
850 Payload.qWrite(aResolutionms);
851 Payload.qWrite(aSpeedFactor);
852 Payload.qWrite(aRepeatCount);
853 return this.connection.writeCommand(IC_CREATE_TIMER, Payload.getBuffer());
854 } else
855 return TConnection.ICE_EVENT_NOT_PUBLISHED;
856 }
857
858
859
860
861
862 public int timerCancel(String aTimerName) {
863 return timerBasicCmd(EK_TIMER_CANCEL, aTimerName);
864 }
865
866
867
868
869
870 public int timerPrepare(String aTimerName) {
871 return timerBasicCmd(EK_TIMER_PREPARE, aTimerName);
872 }
873
874
875
876
877
878 public int timerStart(String aTimerName) {
879 return timerBasicCmd(EK_TIMER_START, aTimerName);
880 }
881
882
883
884
885
886 public int timerStop(String aTimerName) {
887 return timerBasicCmd(EK_TIMER_STOP, aTimerName);
888 }
889
890
891
892
893
894
895 public int timerSetSpeed(String aTimerName, double aSpeedFactor) {
896 TByteBuffer Payload = new TByteBuffer();
897 Payload.prepare(aTimerName);
898 Payload.prepare(aSpeedFactor);
899 Payload.prepareApply();
900 Payload.qWrite(aTimerName);
901 Payload.qWrite(aSpeedFactor);
902 return signalEvent(EK_TIMER_SET_SPEED, Payload.getBuffer());
903 }
904
905
906
907
908
909
910
911 public int timerAcknowledgeAdd(String aTimerName, String aClientName) {
912 return timerAcknowledgeCmd(EK_TIMER_ACKNOWLEDGE_LIST_ADD, aTimerName, aClientName);
913 }
914
915
916
917
918
919
920
921 public int timerAcknowledgeRemove(String aTimerName, String aClientName) {
922 return timerAcknowledgeCmd(EK_TIMER_ACKNOWLEDGE_LIST_REMOVE, aTimerName, aClientName);
923 }
924
925
926
927
928
929
930
931
932 public int timerAcknowledge(String aTimerName, String aClientName, int aProposedTimeStep) {
933 TByteBuffer Payload = new TByteBuffer();
934 Payload.prepare(aClientName);
935 Payload.prepare(aTimerName);
936 Payload.prepare(aProposedTimeStep);
937 Payload.prepareApply();
938 Payload.qWrite(aClientName);
939 Payload.qWrite(aTimerName);
940 Payload.qWrite(aProposedTimeStep);
941 return signalEvent(EK_TIMER_ACKNOWLEDGE, Payload.getBuffer());
942 }
943
944
945
946
947
948
949
950 public int logWriteLn(String aLine, TLogLevel aLevel) {
951 TByteBuffer Payload = new TByteBuffer();
952 if (!isPublished() && this.connection.autoPublish)
953 publish();
954 if (isPublished()) {
955 Payload.prepare((int) 0);
956 Payload.prepare(aLine);
957 Payload.prepare(aLevel.ordinal());
958 Payload.prepareApply();
959 Payload.qWrite((int) 0);
960 Payload.qWrite(aLine);
961 Payload.qWrite(aLevel.ordinal());
962 return signalEvent(EK_LOG_WRITELN, Payload.getBuffer());
963 } else
964 return TConnection.ICE_EVENT_NOT_PUBLISHED;
965 }
966 }