-
Notifications
You must be signed in to change notification settings - Fork 13
/
Ros2CallbackInstance.java
172 lines (152 loc) · 4.92 KB
/
Ros2CallbackInstance.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**********************************************************************
* Copyright (c) 2022 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.tracecompass.incubator.internal.ros2.core.model.messages;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.datastore.core.serialization.ISafeByteBufferReader;
import org.eclipse.tracecompass.datastore.core.serialization.ISafeByteBufferWriter;
import org.eclipse.tracecompass.incubator.internal.ros2.core.model.objects.Ros2ObjectHandle;
/**
* Container for ROS 2 callback instance.
*
* @author Christophe Bedard
*/
public class Ros2CallbackInstance extends Ros2Instance<@NonNull Ros2ObjectHandle> {
/** Custom type value ID for this object */
public static final byte CUSTOM_TYPE_ID = 67;
/** CustomStateValueFactory for this object */
@SuppressWarnings("restriction")
public static final @NonNull CustomStateValueFactory ROS2_CALLBACK_INSTANCE_VALUE_FACTORY = Ros2CallbackInstance::read;
private final long fTid;
private final boolean fIsIntraProcess;
private final long fStartTime;
private final long fEndTime;
/**
* Constructor
*
* @param ownerHandle
* the owner handle
* @param tid
* the TID
* @param isIntraProcess
* whether the callback is intra-process or not
* @param startTime
* the start time
* @param endTime
* the end time
*/
public Ros2CallbackInstance(@NonNull Ros2ObjectHandle ownerHandle, long tid, boolean isIntraProcess, long startTime, long endTime) {
super(ownerHandle);
fTid = tid;
fIsIntraProcess = isIntraProcess;
fStartTime = startTime;
fEndTime = endTime;
}
/**
* @return the PID
*/
public @NonNull Ros2ObjectHandle getOwnerHandle() {
return getOriginHandle();
}
/**
* @return the TID
*/
public long getTid() {
return fTid;
}
/**
* @return the intra process flag
*/
public boolean isIntraProcess() {
return fIsIntraProcess;
}
/**
* @return the start time
*/
public long getStartTime() {
return fStartTime;
}
/**
* @return the end time
*/
public long getEndTime() {
return fEndTime;
}
@Override
public int hashCode() {
return Objects.hash(fTid, fIsIntraProcess, fStartTime, fEndTime, super.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
if (!super.equals(obj)) {
return false;
}
Ros2CallbackInstance o = (Ros2CallbackInstance) obj;
return fTid == o.fTid && fIsIntraProcess == o.fIsIntraProcess && fStartTime == o.fStartTime && fEndTime == o.fEndTime;
}
@Override
public String toString() {
return String.format(
"Ros2CallbackInstance: ownerHandle=%s, tid=%d, isIntraProcess=%b, startTime=%d, endTime=%d", //$NON-NLS-1$
super.toString(), fTid, fIsIntraProcess, fStartTime, fEndTime);
}
@Override
protected @NonNull Byte getCustomTypeId() {
return CUSTOM_TYPE_ID;
}
@Override
protected void serializeValue(ISafeByteBufferWriter buffer) {
super.serializeValue(buffer);
buffer.putLong(fTid);
buffer.putInt(fIsIntraProcess ? 1 : 0);
buffer.putLong(fStartTime);
buffer.putLong(fEndTime);
}
/**
* @param buffer
* the buffer
*/
public void serializeObject(@NonNull ISafeByteBufferWriter buffer) {
serializeValue(buffer);
}
@Override
protected int getSerializedValueSize() {
int size = 0;
size += super.getSerializedValueSize();
size += Long.BYTES;
size += Integer.BYTES;
size += Long.BYTES;
size += Long.BYTES;
return size;
}
/**
* @param buffer
* the buffer
* @return the value
*/
public static @NonNull Ros2CallbackInstance read(ISafeByteBufferReader buffer) {
Ros2ObjectHandle ownerHandle = Ros2ObjectHandle.read(buffer);
long tid = buffer.getLong();
boolean isIntraProcess = buffer.getInt() == 1;
long startTime = buffer.getLong();
long endTime = buffer.getLong();
return new Ros2CallbackInstance(ownerHandle, tid, isIntraProcess, startTime, endTime);
}
}