generate message - help

57 zobrazení
Přeskočit na první nepřečtenou zprávu

Marco

nepřečteno,
22. 6. 2012 5:01:2722.06.12
komu: omn...@googlegroups.com

Hi to all,

I have created my .msg file and I notice that the it generates automatically the _m.h and _m.cc. 
I have my .msg like this:

message Packet
{
int source; //id de source
int destination; //id de dest
int hopCount = 0;
int portsource; //port source
int portdestination; //port dest
}

My function generate message is like this:

Packet *PControl::generateMessage()
{
int src = getId(); // our module id
int dest = 0;
int portdest=0;
char msgname[40];
sprintf(msgname, "Pacote-%d-to-%d", src, dest);

cGate *Port = gate("gate$o",0);

Packet *msg = new Packet(msgname);
msg->setSource(src);
msg->setDestination(dest);
msg->setPortsource(Port->getId());
msg->setPortdestination(portdest);
return msg;
}

After the message been generated I send it in the function forward message.
When this message arrives to the next computer or machine destination, instead of create a new message I want to add to this message (not to create a new one) the new src and destination and do again the: msg->setSource(src); msg->setDestination(dest); msg->setPortsource(Port->getId()); msg->setPortdestination(portdest);- but without lose the previous information already inserted. 

Please can someone tell me how can I do this and keep adding data to the message that will be travel between my machines in the network?
Here I use an "char msgname[40]" for the message that will grow because new fields will be added do you think this is the best variable to do this?

Advises will be very appreciated, please
Regards,
Marco

L. Jacob Mariscal Fernández

nepřečteno,
22. 6. 2012 7:26:0122.06.12
komu: omn...@googlegroups.com

 I think it will be better to use :
const char* msgname; // so it will be not fixed

Then can cuse from string.h strcat function
Hope it will helps.

Marco

nepřečteno,
22. 6. 2012 9:16:3522.06.12
komu: omn...@googlegroups.com
Hi,

thanks for the tip, you are saying to substitute char msgname[40]; for const char* msgname; - where the size will not be fixed. The other things maintain.
If I still want to do sprintf(msgname, "Pacote-%d-to-%d", src, dest); how can I put the msgname there?
sorry if this is a simple question but I'm beginning with C and C++.

Other advises fell free to give.
Regards,
Marco
Odpovědět všem
Odpověď autorovi
Přeposlat
0 nových zpráv