File: evd-utils.c

package info (click to toggle)
event-dance 0.1.20-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 5,068 kB
  • sloc: ansic: 25,946; sh: 11,340; makefile: 418; xml: 249; python: 27
file content (88 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download | duplicates (5)
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
/*
 * evd-utils.c
 *
 * EventDance, Peer-to-peer IPC library <http://eventdance.org>
 *
 * Copyright (C) 2009/2010, Igalia S.L.
 *
 * Authors:
 *   Eduardo Lima Mitev <elima@igalia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 3, or (at your option) any later version as published by
 * the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License at http://www.gnu.org/licenses/lgpl-3.0.txt
 * for more details.
 */

#include <time.h>
#include <uuid/uuid.h>

#include "evd-utils.h"

/**
 * evd_timeout_add:
 * @context: (allow-none):
 * @callback: (scope notified):
 * @user_data: (allow-none):
 *
 **/
guint
evd_timeout_add (GMainContext *context,
                 guint         timeout,
                 gint          priority,
                 GSourceFunc   callback,
                 gpointer      user_data)
{
  guint src_id;
  GSource *src;

  if (context == NULL)
    context = g_main_context_get_thread_default ();

  if (timeout == 0)
    src = g_idle_source_new ();
  else
    src = g_timeout_source_new (timeout);

  g_source_set_priority (src, priority);

  g_source_set_callback (src,
                         callback,
                         user_data,
                         NULL);
  src_id = g_source_attach (src, context);
  g_source_unref (src);

  return src_id;
}

void
evd_nanosleep (gulong nanoseconds)
{
  struct timespec delay;

  delay.tv_sec = 0;
  delay.tv_nsec = nanoseconds;

  nanosleep (&delay, NULL);
}

gchar *
evd_uuid_new (void)
{
  uuid_t uuid;
  gchar *uuid_st = NULL;

  uuid_st = g_new (gchar, 37);

  uuid_generate (uuid);
  uuid_unparse (uuid, uuid_st);

  return uuid_st;
}