IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

aide pour comprendre un code


Sujet :

C++

  1. #1
    Membre actif
    Inscrit en
    Février 2007
    Messages
    406
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 406
    Points : 207
    Points
    207
    Par défaut aide pour comprendre un code
    bonsoir,
    je suis entrain de "décripter" un long code en c++ qui me fait tourner la tête, 'jaurais besoin de vous pour m'aider à comprendre quelque bouts:
    voici en premier lieu la ligne suivante:
    int Agent::uidcnt_;
    dans mon fichier .h , uidcnt_ est variable protected int static ce qui explique qu'on l'appelle précédé par le nom de la classe, la question qui se pose, pourquoi appeler une variable comme sa! alors qu'il n'ya ni affectation ni rien du tout!
    c'est même pas une déclaration puisque je l'ai trouvé dans mon fichier .cc
    j'ai pas posté les deux .h et .cc car ils sont trés long.
    merci de m'aider ^^

  2. #2
    Membre actif
    Étudiant
    Inscrit en
    Octobre 2007
    Messages
    189
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2007
    Messages : 189
    Points : 213
    Points
    213
    Par défaut
    Très bonne question. Mais tu auras meilleur réponse si tu demandes à l'auteur des fichiers en question.

  3. #3
    Membre actif
    Inscrit en
    Février 2007
    Messages
    406
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 406
    Points : 207
    Points
    207
    Par défaut
    je le connais pas!
    bref je poste quand même les codes, peut être qu'un truc m'a echappé!
    *agent.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    /* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
     
    #ifndef ns_agent_h
    #define ns_agent_h
     
    #include "connector.h"
    #include "packet.h"
    #include "timer-handler.h"
    #include "ns-process.h"
    #include "app.h"
    //#include "basetrace.h"
    #define TIME_FORMAT "%.15g"
    // TIME_FORMAT is in basetrace.h, but including that header leads to problems
     
     
    #define TIMER_IDLE 0
    #define TIMER_PENDING 1
     
    /* 
     * Note that timers are now implemented using timer-handler.{cc,h}
     */
     
    #define TRACEVAR_MAXVALUELENGTH 128
     
    class Application;
     
     
    // store old value of traced vars
    // work only for TracedVarTcl
    struct OldValue {
    	TracedVar *var_;
    	char val_[TRACEVAR_MAXVALUELENGTH];
    	struct OldValue *next_;
    };
     
    class EventTrace;
    class Agent : public Connector {
     public:
    	Agent(packet_t pktType);
    	virtual ~Agent();
    	void recv(Packet*, Handler*);
     
    	//added for edrop tracing - ratul
    	void recvOnly(Packet *) {};
     
    	void send(Packet* p, Handler* h) { target_->recv(p, h); }
    	virtual void timeout(int tno);
     
    	virtual void sendmsg(int sz, AppData*, const char* flags = 0);
    	virtual void send(int sz, AppData *data) { sendmsg(sz, data, 0); }
    	virtual void sendto(int sz, AppData*, const char* flags,
    			    nsaddr_t dst);
    	virtual void sendto(int sz, AppData*, const char* flags,
    			    ns_addr_t dst);
     
    	virtual void sendmsg(int nbytes, const char *flags = 0);
    	virtual void send(int nbytes) { sendmsg(nbytes); }
    	virtual void sendto(int nbytes, const char* flags, nsaddr_t dst);
    	virtual void sendto(int nbytes, const char* flags, ns_addr_t dst);
    	virtual void connect(nsaddr_t dst);
    	virtual void close();
    	virtual void listen();
    	virtual void attachApp(Application* app);
    	virtual int& size() { return size_; }
    	inline nsaddr_t& addr() { return here_.addr_; }
    	inline nsaddr_t& port() { return here_.port_; }
    	inline nsaddr_t& daddr() { return dst_.addr_; }
    	inline nsaddr_t& dport() { return dst_.port_; }
    	void set_pkttype(packet_t pkttype) { type_ = pkttype; }
    	inline packet_t get_pkttype() { return type_; }
     
     protected:
    	int command(int argc, const char*const* argv);
    	virtual void delay_bind_init_all();
    	virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
     
    	virtual void recvBytes(int bytes);
    	virtual void idle();
    	Packet* allocpkt() const;	// alloc + set up new pkt
    	Packet* allocpkt(int) const;	// same, but w/data buffer
    	void initpkt(Packet*) const;	// set up fields in a pkt
     
    	ns_addr_t here_;		// address of this agent
    	ns_addr_t dst_;			// destination address for pkt flow
    	int size_;			// fixed packet size
    	packet_t type_;			// type to place in packet header
    	int fid_;			// for IPv6 flow id field
    	int prio_;			// for IPv6 prio field
    	int flags_;			// for experiments (see ip.h)
    	int defttl_;			// default ttl for outgoing pkts
     
    #ifdef notdef
    	int seqno_;		/* current seqno */
    	int class_;		/* class to place in packet header */
    #endif
     
    	static int uidcnt_;
     
    	Tcl_Channel channel_;
    	char *traceName_;		// name used in agent traces
    	OldValue *oldValueList_; 
     
    	Application *app_;		// ptr to application for callback
     
    	virtual void trace(TracedVar *v);
    	void deleteAgentTrace();
    	void addAgentTrace(const char *name);
    	void monitorAgentTrace();
    	OldValue* lookupOldValue(TracedVar *v);
    	void insertOldValue(TracedVar *v, const char *value);
    	void dumpTracedVars();
     
    	/* support for event-tracing */
            EventTrace *et_;
            virtual void trace_event(char *eventtype){}
     
     private:
    	void flushAVar(TracedVar *v);
    };
     
    #endif
    *agent.cc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    /* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
     
     
    #ifndef lint
    static const char rcsid[] =
        "@(#) $Header: /cvsroot/nsnam/ns-2/common/agent.cc,v 1.79 2006/02/21 15:20:17 mahrenho Exp $ (LBL)";
    #endif
     
    #include <assert.h>
    #include <stdlib.h>
     
    #include "config.h"
    #include "agent.h"
    #include "ip.h"
    #include "flags.h"
    #include "address.h"
    #include "app.h"
    #ifdef HAVE_STL
    #include "nix/hdr_nv.h"
    #include "nix/nixnode.h"
    #endif //HAVE_STL
     
     
     
    #ifndef min
    #define min(a, b) (((a) < (b)) ? (a) : (b))
    #endif
     
    static class AgentClass : public TclClass {
    public:
    	AgentClass() : TclClass("Agent") {} 
    	TclObject* create(int, const char*const*) {
    		return (new Agent(PT_NTYPE));
    	}
    } class_agent;
     
    int Agent::uidcnt_;		/* running unique id */
     
    Agent::Agent(packet_t pkttype) : 
    	size_(0), type_(pkttype), 
    	channel_(0), traceName_(NULL),
    	oldValueList_(NULL), app_(0), et_(0)
    {
    }
     
    void
    Agent::delay_bind_init_all()
    {
    	delay_bind_init_one("agent_addr_");
    	delay_bind_init_one("agent_port_");
    	delay_bind_init_one("dst_addr_");
    	delay_bind_init_one("dst_port_");
    	delay_bind_init_one("fid_");
    	delay_bind_init_one("prio_");
    	delay_bind_init_one("flags_");
    	delay_bind_init_one("ttl_");
    	delay_bind_init_one("class_");
    	Connector::delay_bind_init_all();
    }
     
    int
    Agent::delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer)
    {
    	if (delay_bind(varName, localName, "agent_addr_", (int*)&(here_.addr_), tracer)) return TCL_OK;
    	if (delay_bind(varName, localName, "agent_port_", (int*)&(here_.port_), tracer)) return TCL_OK;
    	if (delay_bind(varName, localName, "dst_addr_", (int*)&(dst_.addr_), tracer)) return TCL_OK;
    	if (delay_bind(varName, localName, "dst_port_", (int*)&(dst_.port_), tracer)) return TCL_OK;
    	if (delay_bind(varName, localName, "fid_", (int*)&fid_, tracer)) return TCL_OK;
    	if (delay_bind(varName, localName, "prio_", (int*)&prio_, tracer)) return TCL_OK;
    	if (delay_bind(varName, localName, "flags_", (int*)&flags_, tracer)) return TCL_OK;
    	if (delay_bind(varName, localName, "ttl_", &defttl_, tracer)) return TCL_OK;
    	if (delay_bind(varName, localName, "class_", (int*)&fid_, tracer)) return TCL_OK;
    	return Connector::delay_bind_dispatch(varName, localName, tracer);
    }
     
     
    Agent::~Agent()
    {
    	if (oldValueList_ != NULL) {
    		OldValue *p = oldValueList_;
    		while (oldValueList_ != NULL) {
    			oldValueList_ = oldValueList_->next_;
    			delete p;
    			p = oldValueList_; 
    		}
    	}
    }
     
    int Agent::command(int argc, const char*const* argv)
    {
    	Tcl& tcl = Tcl::instance();
    	if (argc == 2) {
    		if (strcmp(argv[1], "delete-agent-trace") == 0) {
    			if ((traceName_ == 0) || (channel_ == 0))
    				return (TCL_OK);
    			deleteAgentTrace();
    			return (TCL_OK);
    		} else if (strcmp(argv[1], "show-monitor") == 0) {
    			if ((traceName_ == 0) || (channel_ == 0))
    				return (TCL_OK);
    			monitorAgentTrace();
    			return (TCL_OK);
    		} else if (strcmp(argv[1], "close") == 0) {
    			close();
    			return (TCL_OK);
    		} else if (strcmp(argv[1], "listen") == 0) {
                            listen();
                            return (TCL_OK);
                    } else if (strcmp(argv[1], "dump-namtracedvars") == 0) {
    			enum_tracedVars();
    			return (TCL_OK);
    		}
     
    	}
    	else if (argc == 3) {
    		if (strcmp(argv[1], "attach") == 0) {
    			int mode;
    			const char* id = argv[2];
    			channel_ = Tcl_GetChannel(tcl.interp(), (char*)id, &mode);
    			if (channel_ == 0) {
    				tcl.resultf("trace: can't attach %s for writing", id);
    				return (TCL_ERROR);
    			}
    			return (TCL_OK);
    		} else if (strcmp(argv[1], "add-agent-trace") == 0) {
    			// we need to write nam traces and set agent trace name
    			if (channel_ == 0) {
    				tcl.resultf("agent %s: no trace file attached", name_);
    				return (TCL_OK);
    			}
    			addAgentTrace(argv[2]);
    			return (TCL_OK);
    		} else if (strcmp(argv[1], "connect") == 0) {
    			connect((nsaddr_t)atoi(argv[2]));
    			return (TCL_OK);
    		} else if (strcmp(argv[1], "send") == 0) {
    			sendmsg(atoi(argv[2]));
    			return (TCL_OK);
    		} else if (strcmp(argv[1], "set_pkttype") == 0) {
    			set_pkttype(packet_t(atoi(argv[2])));
    			return (TCL_OK);
    		}
    	}
    	else if (argc == 4) {	
    		if (strcmp(argv[1], "sendmsg") == 0) {
    			sendmsg(atoi(argv[2]), argv[3]);
    			return (TCL_OK);
    		}
    	}
    	else if (argc == 5) {
    		if (strcmp(argv[1], "sendto") == 0) {
    			sendto(atoi(argv[2]), argv[3], (nsaddr_t)atoi(argv[4]));
    			return (TCL_OK);
    		}
    	}
    	if (strcmp(argv[1], "tracevar") == 0) {
    		// wrapper of TclObject's trace command, because some tcl
    		// agents (e.g. srm) uses it.
    		const char* args[4];
    		char tmp[6];
    		strcpy(tmp, "trace");
    		args[0] = argv[0];
    		args[1] = tmp;
    		args[2] = argv[2];
    		if (argc > 3)
    			args[3] = argv[3];
    		return (Connector::command(argc, args));
    	}
    	return (Connector::command(argc, argv));
    }
     
    void Agent::flushAVar(TracedVar *v)
    {
    	char wrk[256], value[128];
    	int n;
     
    	// XXX we need to keep track of old values. What's the best way?
    	v->value(value, 128);
    	if (strcmp(value, "") == 0) 
    		// no value, because no writes has occurred to this var
    		return;
    	sprintf(wrk, "f -t "TIME_FORMAT" -s %d -d %d -n %s -a %s -o %s -T v -x",
    		Scheduler::instance().clock(), addr(), dst_.addr_,
    		v->name(), traceName_, value); 
    	n = strlen(wrk);
    	wrk[n] = '\n';
    	wrk[n+1] = 0;
    	(void)Tcl_Write(channel_, wrk, n+1);
    }
     
    void Agent::deleteAgentTrace()
    {
    	char wrk[256];
     
    	// XXX we don't know InstVar outside of Tcl! Is there any
    	// tracedvars hidden in InstVar? If so, shall we have a tclclInt.h?
    	TracedVar* var = tracedvar_;
    	for ( ;  var != 0;  var = var->next_) 
    		flushAVar(var);
     
    	// we need to flush all var values to trace file, 
    	// so nam can do backtracing
    	sprintf(wrk, "a -t "TIME_FORMAT" -s %d -d %d -n %s -x",
    		Scheduler::instance().clock(), here_.addr_,
    		dst_.addr_, traceName_); 
    	if (traceName_ != NULL)
    		delete[] traceName_;
    	traceName_ = NULL;
    }
     
    OldValue* Agent::lookupOldValue(TracedVar *v)
    {
    	OldValue *p = oldValueList_;
    	while ((p != NULL) && (p->var_ != v))
    		p = p->next_;
    	return p;
    }
     
    void Agent::insertOldValue(TracedVar *v, const char *value)
    {
    	OldValue *p = new OldValue;
    	assert(p != NULL);
    	strncpy(p->val_, value, min(strlen(value)+1, TRACEVAR_MAXVALUELENGTH));
    	p->var_ = v;
    	p->next_ = NULL;
    	if (oldValueList_ == NULL) 
    		oldValueList_ = p;
    	else {
    		p->next_ = oldValueList_;
    		oldValueList_ = p;
    	}
    }
     
    // callback from traced variable updates
    void Agent::trace(TracedVar* v) 
    {
    	if (channel_ == 0)
    		return;
    	char wrk[256], value[128];
    	int n;
     
    	// XXX we need to keep track of old values. What's the best way?
    	v->value(value, 128);
     
    	// XXX hack: how do I know ns has not started yet?
    	// if there's nothing in value, return
    	static int started = 0;
    	if (!started) {
    		Tcl::instance().evalc("[Simulator instance] is-started");
    		if (Tcl::instance().result()[0] == '0')
    			// Simulator not started, do nothing
    			return;
    		// remember for next time (so we don't always have to call to tcl)
    		started = 1;
    	};
     
    	OldValue *ov = lookupOldValue(v);
    	if (ov != NULL) {
    		sprintf(wrk, 
    			"f -t "TIME_FORMAT" -s %d -d %d -n %s -a %s -v %s -o %s -T v",
    			Scheduler::instance().clock(), here_.addr_,
    			dst_.addr_, v->name(), traceName_, value, ov->val_);
    		strncpy(ov->val_, 
    			value,
    			min(strlen(value)+1, TRACEVAR_MAXVALUELENGTH));
    	} else {
    		// if there is value, insert it into old value list
    		sprintf(wrk, "f -t "TIME_FORMAT" -s %d -d %d -n %s -a %s -v %s -T v",
    			Scheduler::instance().clock(), here_.addr_,
    			dst_.addr_, v->name(), traceName_, value);
    		insertOldValue(v, value);
    	}
    	n = strlen(wrk);
    	wrk[n] = '\n';
    	wrk[n+1] = 0;
    	(void)Tcl_Write(channel_, wrk, n+1);
    }
     
    void Agent::monitorAgentTrace()
    {
    	char wrk[256];
    	int n;
    	double curTime = (&Scheduler::instance() == NULL ? 0 : 
    			  Scheduler::instance().clock());
     
    	sprintf(wrk, "v -t "TIME_FORMAT" -e monitor_agent %d %s",
    		curTime, here_.addr_, traceName_);
    	n = strlen(wrk);
    	wrk[n] = '\n';
    	wrk[n+1] = 0;
    	if (channel_)
    		(void)Tcl_Write(channel_, wrk, n+1);
    }
     
    void Agent::addAgentTrace(const char *name)
    {
    	char wrk[256];
    	int n;
    	double curTime = (&Scheduler::instance() == NULL ? 0 : 
    			  Scheduler::instance().clock());
     
    	sprintf(wrk, "a -t "TIME_FORMAT" -s %d -d %d -n %s",
    		curTime, here_.addr_, dst_.addr_, name);
    	n = strlen(wrk);
    	wrk[n] = '\n';
    	wrk[n+1] = 0;
    	if (channel_)
    		(void)Tcl_Write(channel_, wrk, n+1);
    	// keep agent trace name
    	if (traceName_ != NULL)
    		delete[] traceName_;
    	traceName_ = new char[strlen(name)+1];
    	strcpy(traceName_, name);
    }
     
    void Agent::timeout(int)
    {
    }
     
    /* 
     * Callback to application to notify the reception of a number of bytes  
     */
    void Agent::recvBytes(int nbytes)
    {
    	if (app_)
    		app_->recv(nbytes);	
    }
     
    /* 
     * Callback to application to notify the termination of a connection  
     */
    void Agent::idle()
    {
    	if (app_)
    		app_->resume();
    }
     
    /* 
     * Assign application pointer for callback purposes    
     */
    void Agent::attachApp(Application *app)
    {
    	app_ = app;
    }
     
    void Agent::close()
    {
    }
     
    void Agent::listen()
    {
    }
     
    /* 
     * This function is a placeholder in case applications want to dynamically
     * connect to agents (presently, must be done at configuration time).
     */
    void Agent::connect(nsaddr_t /*dst*/)
    {
    /*
    	dst_ = dst;
    */
    }
     
    /*
     * Place holders for sending application data
     */ 
     
    void Agent::sendmsg(int /*sz*/, AppData* /*data*/, const char* /*flags*/)
    {
    	fprintf(stderr, 
    	"Agent::sendmsg(int, AppData*, const char*) not implemented\n");
    	abort();
    }
     
    void Agent::sendmsg(int /*nbytes*/, const char* /*flags*/)
    {
    }
     
    void Agent::sendto(int /*sz*/, AppData* /*data*/, const char* /*flags*/,
    		   nsaddr_t /*dst*/)
    {
    	fprintf(stderr, 
    	"Agent::sendmsg(int, AppData*, const char*) not implemented\n");
    	abort();
    }
     
    // to support application using message passing
    void Agent::sendto(int /*sz*/, AppData* /*data*/, const char* /*flags*/,
    		   ns_addr_t /*dst*/)
    {
    }
     
    /* 
     * This function is a placeholder in case applications want to dynamically
     * connect to agents (presently, must be done at configuration time).
     */
    void Agent::sendto(int /*nbytes*/, const char /*flags*/[], nsaddr_t /*dst*/)
    {
    /*
    	dst_ = dst;
    	sendmsg(nbytes, flags);
    */
    }
    // to support application using message passing
    void Agent::sendto(int /*nbytes*/, const char /*flags*/[], ns_addr_t /*dst*/)
    {
    }
     
    void Agent::recv(Packet* p, Handler*)
    {
    	if (app_)
    		app_->recv(hdr_cmn::access(p)->size());
    	/*
    	 * didn't expect packet (or we're a null agent?)
    	 */
    	Packet::free(p);
    }
     
    /*
     * initpkt: fill in all the generic fields of a pkt
     */
     
    void
    Agent::initpkt(Packet* p) const
    {
    	hdr_cmn* ch = hdr_cmn::access(p);
    	ch->uid() = uidcnt_++;
    	ch->ptype() = type_;
    	ch->size() = size_;
    	ch->timestamp() = Scheduler::instance().clock();
    	ch->iface() = UNKN_IFACE.value(); // from packet.h (agent is local)
    	ch->direction() = hdr_cmn::NONE;
     
    	ch->error() = 0;	/* pkt not corrupt to start with */
     
    	hdr_ip* iph = hdr_ip::access(p);
    	iph->saddr() = here_.addr_;
    	iph->sport() = here_.port_;
    	iph->daddr() = dst_.addr_;
    	iph->dport() = dst_.port_;
     
    	//DEBUG
    	//if (dst_ != -1)
    	//  printf("pl break\n");
     
    	iph->flowid() = fid_;
    	iph->prio() = prio_;
    	iph->ttl() = defttl_;
     
    	hdr_flags* hf = hdr_flags::access(p);
    	hf->ecn_capable_ = 0;
    	hf->ecn_ = 0;
    	hf->eln_ = 0;
    	hf->ecn_to_echo_ = 0;
    	hf->fs_ = 0;
    	hf->no_ts_ = 0;
    	hf->pri_ = 0;
    	hf->cong_action_ = 0;
    	hf->qs_ = 0;
    #ifdef HAVE_STL
     
     	hdr_nv* nv = hdr_nv::access(p);
     	if (0)
    		printf("Off hdr_nv %d, ip_hdr %d myaddr %d\n",
    		       hdr_nv::offset(), hdr_ip::offset(), here_.addr_);
     	NixNode* pNixNode = NixNode::GetNodeObject(here_.addr_);
    	// 	if (0)
    	//		printf("Node Object %p\n", reinterpret_cast<void *>(pNixNode) );
     	if (pNixNode) { 
     		// If we get non-null, indicates nixvector routing in use
     		// Delete any left over nv in the packet
     		// Get a nixvector to the target (may create new)
     		NixVec* pNv = pNixNode->GetNixVector(dst_.addr_);
     		pNv->Reset();
     		nv->nv() = pNv; // And set the nixvec in the packet
     		nv->h_used = 0; // And reset used portion to 0
     	}
    #endif //HAVE_STL
    }
     
    /*
     * allocate a packet and fill in all the generic fields
     */
    Packet*
    Agent::allocpkt() const
    {
    	Packet* p = Packet::alloc();
    	initpkt(p);
    	return (p);
    }
     
    /* allocate a packet and fill in all the generic fields and allocate
     * a buffer of n bytes for data
     */
    Packet*
    Agent::allocpkt(int n) const
    {
            Packet* p = allocpkt();
     
    	if (n > 0)
    	        p->allocdata(n);
     
    	return(p);
    }

  4. #4
    Rédacteur/Modérateur
    Avatar de JolyLoic
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2004
    Messages
    5 463
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2004
    Messages : 5 463
    Points : 16 213
    Points
    16 213
    Ma session aux Microsoft TechDays 2013 : Développer en natif avec C++11.
    Celle des Microsoft TechDays 2014 : Bonnes pratiques pour apprivoiser le C++11 avec Visual C++
    Et celle des Microsoft TechDays 2015 : Visual C++ 2015 : voyage à la découverte d'un nouveau monde
    Je donne des formations au C++ en entreprise, n'hésitez pas à me contacter.

  5. #5
    Membre actif
    Inscrit en
    Février 2007
    Messages
    406
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 406
    Points : 207
    Points
    207
    Par défaut
    merci bcp JolyLoic
    le premier lien m'eclaircit bcp la chose, mais juste une ptite question qui me reste:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Fred.cpp 
     
    #include "Fred.h"
     
    int Fred::j_ = some_expression_evaluating_to_an_int;
     
    // A côté de ça, si vous souhaitez utiliser la valeur implicite des entiers static :
    // int Fred::j_;
    valeur implicite, c'est a dire , on assigne a j_ rien du tout, n'est ce pas?
    merci encore^^

  6. #6
    Rédacteur/Modérateur
    Avatar de JolyLoic
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2004
    Messages
    5 463
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2004
    Messages : 5 463
    Points : 16 213
    Points
    16 213
    Par défaut
    Pour un entier statique, la valeur d'initialisation si rien n'est précisé est 0 (mais je trouve que c'est plus clair de marquer =0 explicitement). Un entier qui serait une variable locale lui n'aurait aucune valeur définie. Et pour une instance de classe définie sans précision, ce serait le constructeur par défaut de la classe qui serait utilisé.
    Ma session aux Microsoft TechDays 2013 : Développer en natif avec C++11.
    Celle des Microsoft TechDays 2014 : Bonnes pratiques pour apprivoiser le C++11 avec Visual C++
    Et celle des Microsoft TechDays 2015 : Visual C++ 2015 : voyage à la découverte d'un nouveau monde
    Je donne des formations au C++ en entreprise, n'hésitez pas à me contacter.

Discussions similaires

  1. Aide pour comprendre un code
    Par Go'Gaule dans le forum Débuter
    Réponses: 5
    Dernier message: 23/07/2011, 17h08
  2. [AC-2007] besoin d'aide pour comprendre un code pour FTP trouvé sur le forum
    Par tibofo dans le forum VBA Access
    Réponses: 2
    Dernier message: 25/04/2010, 20h03
  3. Besoin d aide pour comprendre un code
    Par litlebasic dans le forum Delphi
    Réponses: 4
    Dernier message: 22/06/2006, 13h00
  4. Aide pour comprendre un code
    Par Spacy_green dans le forum Assembleur
    Réponses: 2
    Dernier message: 13/02/2006, 13h22
  5. Aide pour comprendre le code
    Par jfreuff dans le forum Assembleur
    Réponses: 2
    Dernier message: 31/01/2006, 17h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo