blob: f10dc70d51691826ad08ad5a634595c8aadb53a9 [file] [log] [blame]
Alexander Afanasyevca6f3292012-04-09 10:03:30 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * Chaoyi Bian <bcy@pku.edu.cn>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#ifndef SYNC_SCHEDULER_H
24#define SYNC_SCHEDULER_H
25
Alexander Afanasyev181d7e52012-04-09 13:54:11 -070026#include <ns3/nstime.h>
27#include <ns3/event-id.h>
28#include <list>
29#include <map>
30
Alexander Afanasyevca6f3292012-04-09 10:03:30 -070031#include "sync-event.h"
32
Alexander Afanasyev181d7e52012-04-09 13:54:11 -070033#define TIME_SECONDS(number) ns3::Seconds(number)
34#define TIME_MILLISECONDS(number) ns3::MilliSeconds(number)
35typedef ns3::Time TimeDuration;
36
Alexander Afanasyevca6f3292012-04-09 10:03:30 -070037namespace Sync {
38
39/**
40 * @ingroup sync
41 * @brief General purpose event scheduler
42 *
43 * This class internally runs a thread and events can be scheduled by specifying an absolute or relative time of the event
44 */
45class Scheduler
46{
47public:
48 /**
49 * @brief Default constructor. Thread will be created
50 */
51 Scheduler ();
52 /**
53 * @brief Destructor. Thread will be nicely stopped
54 */
55 ~Scheduler ();
56
57 /**
58 * @brief Schedule an event at absolute time 'abstime'
59 * @param abstime Absolute time
60 * @param event function to be called at the time
61 * @param label Label for the event
62 */
63 // void
64 // schedule (const boost::system_time &abstime, Event event, uint32_t label);
65
66 /**
67 * @brief Schedule an event at relative time 'reltime'
68 * @param reltime Relative time
69 * @param event function to be called at the time
70 * @param label Label for the event
71 */
72 void
Alexander Afanasyev181d7e52012-04-09 13:54:11 -070073 schedule (const TimeDuration &reltime, Event event, uint32_t label);
Alexander Afanasyevca6f3292012-04-09 10:03:30 -070074
75 /**
76 * @brief Cancel all events for the label
77 * @param label Label of the event that needs to be cancelled
78 */
79 void
80 cancel (uint32_t label);
Alexander Afanasyev181d7e52012-04-09 13:54:11 -070081
82private:
83 static void
84 eventWrapper (Event event);
85
86private:
87 std::map< uint32_t, std::list< ns3::EventId > > m_labeledEvents;
Alexander Afanasyevca6f3292012-04-09 10:03:30 -070088};
89
90}
91
92#endif // SYNC_SCHEDULER_H