Statistics
| Branch: | Revision:

napa-baselibs / monl / mon_event.cpp @ a1a78de4

History | View | Annotate | Download (2.3 KB)

1 956892f0 ArpadBakay
/***************************************************************************
2
 *   Copyright (C) 2009 by Robert Birke
3
 *   robert.birke@polito.it
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9

10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14

15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
18
 ***********************************************************************/
19
20
#include "mon_event.h"
21
#include <event2/event.h>
22
23
#include "measure_dispatcher.h"
24
25
struct event_base *eventb = NULL;
26
27
struct measure_disp_pair {
28
        class MeasureDispatcher *ptrDispatcher;
29
        MonHandler mh;
30
};
31
32
void schedule_measure_cb(evutil_socket_t fd, short what, void *arg);
33
void schedule_publish_cb(evutil_socket_t fd, short what, void *arg);
34
35
int schedule_measure(struct timeval *tv, MonMeasure *m) {
36
        struct measure_disp_pair *m_disp = new struct measure_disp_pair;
37
        m_disp->ptrDispatcher = m->ptrDispatcher;
38
        m_disp->mh = m->mh_local;
39
        return event_base_once(eventb, -1, EV_TIMEOUT, schedule_measure_cb, m_disp, tv);
40
}
41
42
int schedule_publish(struct timeval *tv, MonMeasure *m) {
43
        struct measure_disp_pair *m_disp = new struct measure_disp_pair;
44
        m_disp->ptrDispatcher = m->ptrDispatcher;
45
        m_disp->mh = m->mh_local;
46
        return event_base_once(eventb, -1, EV_TIMEOUT, schedule_publish_cb, m_disp, tv);
47
}
48
49
void init_mon_event(void *eb) {
50
        eventb = (struct event_base *) eb;
51
}
52
53
void schedule_measure_cb(evutil_socket_t fd, short what, void *arg) {
54
        struct measure_disp_pair *m_disp = (struct measure_disp_pair *) arg;
55
        m_disp->ptrDispatcher->scheduleMeasure(m_disp->mh);
56
        delete m_disp;
57
}
58
59
void schedule_publish_cb(evutil_socket_t fd, short what, void *arg) {
60
        struct measure_disp_pair *m_disp = (struct measure_disp_pair *) arg;
61
        m_disp->ptrDispatcher->schedulePublish(m_disp->mh);
62
        delete m_disp;
63
}