With the dynamic array sizes you cannot do simple tests to check the size of the incoming packets..basically you just have to trust that player is passing you a valid data packet. If you want to be double certain then you can test that it is at least the size of the base structure...

The len field in publish is actually ignored rather than being optional, The one in Request is also ignored, although it gets passed on for a long time first.

Toby

On 15/11/2007, Paul Osmialowski <newchief@king.net.pl> wrote:
Hi Toby,

I'm trying to rewrite some plugin driver so it could be compiled with CVS
version of libplayercore. As we know, currently Publish() method parameter
that denotes the size of published data packet is optional and has default
value 0, which means, the size of the data can be dynamic and is computed.
In my driver I'm also using Request() method to send
PLAYER_SIMULATION_REQ_GET_POSE2D request, which means I have to fill
fields in player_simulation_pose2d_req_t structure. One of them (called
'name') has dynamic size. Unfortunately, 'len' parameter of Request()
method isn't optional, so I guess I have to pass size of the
player_simulation_pose2d_req_t structure.
My code is:

#define STRNCPY(dest, src, n) do \
{ \
   strncpy(dest, src, n); \
   ((dest)[n-1]) = 0; \
} while (0)

     player_position2d_data_t posdata;
     Message * msg;
     player_simulation_pose2d_req_t posreq, * posreq_new;
     memset(&posdata, 0, sizeof posdata);
     memset(&posreq, 0, sizeof posreq);
     posreq.name_count = strlen(this->object) + 1;
     posreq.name = new char[posreq.name_count ];
     assert(posreq.name);
     STRNCPY(posreq.name, this->object, posreq.name_count);
     msg = this->simulation_dev->Request(this->InQueue,
                                         PLAYER_MSGTYPE_REQ,
                                         PLAYER_SIMULATION_REQ_GET_POSE2D,
                                         (void *)(&posreq),
                                         sizeof posreq,
                                         NULL, true);
     delete []posreq.name;
     posreq.name = NULL;
     if (!msg)
     {
       PLAYER_WARN("failed to acquire position data");
     } else
     {
       if ((msg->GetDataSize()) !=
(sizeof(player_simulation_pose2d_req_t)))
       {
         PLAYER_WARN2("invalid acqired data size %d vs %d",
msg->GetDataSize(), sizeof(player_simulation_pose2d_
req_t));
       } else
       {
         posreq_new = (player_simulation_pose2d_req_t
*)(msg->GetPayload());
         if (!posreq_new)
         {
           PLAYER_WARN("no data acquired");
         } else
         {
           posdata.pos.px = posreq_new->pose.px;
           posdata.pos.py = posreq_new->pose.py;
           posdata.pos.pa = posreq_new->pose.pa;
         }
       }
       delete msg;
     }
     msg = NULL;

As a result I'm getting warning:
invalid acqired data size 35 vs 32

What went wrong?
This code worked before recent changes...

Cheers,
Paul


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Playerstage-developers mailing list
Playerstage-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-developers



--
This email is intended for the addressee only and may contain privileged and/or confidential information