Hi guys,
This morning I observed a strange error while trying to have handlers modify my service state.
So here's the situation. I have 2 simulated cameras attached on a simulated robot entity. Every 50 miliseconds, the TimerPortHandler will post 2 messages to get the cameras to take 2 pictures and store the byte[] into 2 service states
members (of type byte[] also).
So here's the brief code:
TimerHandler:
void
TimerHandler(DateTime signal){
new IncrementTick());_mainPort.Post(
_mainPort.Post(
new GetUpdateFromJoints());_mainPort.Post(
new GetUpdateFromLeftCamera());//first camera takes pix_mainPort.Post(
new GetUpdateFromRightCamera());//second camera takes pixActivate(
Arbiter.Receive(false, TimeoutPort(100),delegate(DateTime time)
{
_timerPort.Post(time);
}
)
);
}
First Camera:
[
ServiceHandler(ServiceHandlerBehavior.Exclusive)] public IEnumerator<ITask> GetUpdateFromLeftCameraHandler(GetUpdateFromLeftCamera getUpdateFromLeftCamera){
if (rover.RobotsLeftCamera != null)
{
ImageFormat.Bmp, _leftCameraPort); yield return Arbiter.Choice(_leftCameraPort,rover.RobotsLeftCamera.CaptureScene(
delegate(Bitmap b)
{
MemoryStream stream = new System.IO.MemoryStream();System.IO.
b.Save(stream,
ImageFormat.Bmp); byte[] byteResult = new byte[stream.Length];byteResult = stream.ToArray();
stream.Close();
_state.ByteLeft =
new byte[byteResult.Length];_state.ByteLeft = byteResult;
},
delegate(Exception ex){
}
);
}
getUpdateFromLeftCamera.ResponsePort.Post(
DefaultUpdateResponseType.Instance); yield break;}
Second Camera:
[
ServiceHandler(ServiceHandlerBehavior.Exclusive)] public IEnumerator<ITask> GetUpdateFromRightCameraHandler(GetUpdateFromRightCamera getUpdateFromRightCamera){
if (rover.RobotsRightCamera != null)
{
ImageFormat.Bmp, _rightCameraPort); yield return Arbiter.Choice(_rightCameraPort,rover.RobotsRightCamera.CaptureScene(
delegate(Bitmap b)
{
MemoryStream stream2 = new System.IO.MemoryStream();System.IO.
b.Save(stream2,
ImageFormat.Bmp); byte[] byteResult = new byte[stream2.Length];byteResult = stream2.ToArray();
stream2.Close();
_state.ByteRight =
new byte[byteResult.Length];_state.ByteRight = byteResult;
},
delegate(Exception ex){
}
);
}
getUpdateFromRightCamera.ResponsePort.Post(
DefaultUpdateResponseType.Instance); yield break;}
Now, when the GetUpdateFromLeftCameraHandler and GetUpdateFromRightCameraHandler are marked "Exclusive", nothing works, like this service doesnt seem to update any of its state members at all (I have a subsriber to listen to any of these state changes).
Strangely enough, when the ServiceHandlerBehaviors are marked to "Concurrent" everything works out nicely.
I learned from the Service Tutorials that if a handler is trying to modify a state, it should be doing it exclusively, not concurrently. Therefore, I dont feel right with this solution.
Could anyone tell me what happened there and the solution to this
Thanks guys,