problem about periodically call a function

65 views
Skip to first unread message

Peng Wang

unread,
Mar 22, 2014, 2:52:16 AM3/22/14
to ns-3-...@googlegroups.com
Hi All

I write a program in scratch/ folder, which will call function A (eg, print a word)in src/ folder periodically. Through searching the Internet, I find that it can be realized by inserting Simulator::Schedule(call_interval, &function A, this) in function A to call function itself after a specific time. The question is, how I can call function A from my program in scratch/? I have tried something like the following line. "Simulator::Schedule (Seconds (0.0), &ns3::ClassA::functionA)". There is no error during compiling and executing processes. However, no word is printed on my screen. 

Why? Is something wrong with this method? 

Grateful for any assistance!        

Tommaso Pecorella

unread,
Mar 22, 2014, 3:04:20 AM3/22/14
to ns-3-...@googlegroups.com
Hi,

if there's no error during compilation/run, then the problem may be in the printing. Isn't it ?

What's inside your functionA ?

T.

Peng Wang

unread,
Mar 22, 2014, 3:14:03 AM3/22/14
to ns-3-...@googlegroups.com
Thanks for your time and response!

just one sentence: std::cout << "print word"; Logically, it should be executed periodically, since I have started to execute it at "0.0s" in program in "scratch/".
Is there something wrong with this line: "Simulator::Schedule (Seconds (0.0), &ns3::ClassA::functionA)"?  

By the way, if you want to schedule an event in another program, what you will do?

Tommaso Pecorella

unread,
Mar 22, 2014, 3:28:22 AM3/22/14
to ns-3-...@googlegroups.com
"Simulator::Schedule (Seconds (0.0), &ns3::ClassA::functionA)" is correct, but "ns3::ClassA::functionA" must be a static function in the class (you didn't specify the third argument, the instance's pointer).

"std::cout << "print word";" is correct, but you didn't add a newline at the end of it. This may lead to buffer issues: the output will be printed when the program terminates.

Launching a function in another program... no, not possible (if by "program" you mean a different simulation).

T.

Peng Wang

unread,
Mar 22, 2014, 4:45:58 AM3/22/14
to ns-3-...@googlegroups.com
Oh, yes. it really helps. They are in different simulations. My idea seems not correct. 

In fact, it is something related to my research. I scheduled an event in program A to make the value of some variables be updated periodically. In Program B, I will start the simulation, and also want to start the event in program A. 

I really have no ideas by now. Can you give me some directions?

Thanks again for your help!   
Reply all
Reply to author
Forward
0 new messages