summaryrefslogtreecommitdiff
path: root/common/distrio_error.h
blob: 36b6c93bfb1f3d4479344fb629810c409e4f8f6d (plain)
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
/**
 * distrio error helper
 *
 *  - inline functions to ease handling of Distrio::Error
 *
 * @author Manuel Traut <manut@mecka.net>
 * @licence GPLv2
 */

#include <time.h>

inline Distrio::Error *distrio_error (::Distrio::Error_code code,
	::Distrio::Error_level level,
	long module_id,
	std::string description)
{
	struct timespec ts;
	Distrio::Error *e = new Distrio::Error;

	clock_gettime (CLOCK_REALTIME, &ts);

	e->code = code;
	e->level = level;
	e->time.seconds = ts.tv_sec;
	e->time.nanoseconds = ts.tv_nsec;
	e->module_id = module_id;
	e->description = CORBA::string_dup (description.c_str ());

	return e;
}

inline Distrio::Error *distrio_success (void) {
	struct timespec ts;
	Distrio::Error *e = new Distrio::Error;

	clock_gettime (CLOCK_REALTIME, &ts);

	e->code = Distrio::SUCCESS;
	e->level = Distrio::L_DEBUG;
	e->time.seconds = ts.tv_sec;
	e->time.nanoseconds = ts.tv_nsec;
	e->module_id = 0;
	e->description = CORBA::string_dup (__func__);

	return e;
}