reimplemented dbus plugin for NetworkManager 0.7, renamed to nm
[strongswan.git] / src / charon / plugins / nm / nm_plugin.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include "nm_plugin.h"
19 #include "nm_service.h"
20
21 #include <daemon.h>
22 #include <processing/jobs/callback_job.h>
23
24 typedef struct private_nm_plugin_t private_nm_plugin_t;
25
26 /**
27 * private data of nm plugin
28 */
29 struct private_nm_plugin_t {
30
31 /**
32 * implements plugin interface
33 */
34 nm_plugin_t public;
35
36 GMainLoop *loop;
37 };
38
39 /**
40 * NM plugin processing routine, creates and handles NMVPNPlugin
41 */
42 static job_requeue_t run(private_nm_plugin_t *this)
43 {
44 NMStrongswanPlugin *plugin;
45 GMainLoop *loop;
46
47 plugin = nm_strongswan_plugin_new();
48
49 this->loop = loop = g_main_loop_new(NULL, FALSE);
50 g_main_loop_run(loop);
51
52 g_main_loop_unref(loop);
53 g_object_unref(plugin);
54
55 return JOB_REQUEUE_NONE;
56 }
57
58 /**
59 * Implementation of plugin_t.destroy
60 */
61 static void destroy(private_nm_plugin_t *this)
62 {
63 if (this->loop)
64 {
65 g_main_loop_quit(this->loop);
66 }
67 free(this);
68 }
69
70 /*
71 * see header file
72 */
73 plugin_t *plugin_create()
74 {
75 private_nm_plugin_t *this = malloc_thing(private_nm_plugin_t);
76
77 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
78
79 this->loop = NULL;
80 g_type_init ();
81 if (!g_thread_supported())
82 {
83 g_thread_init(NULL);
84 }
85
86 charon->processor->queue_job(charon->processor,
87 (job_t*)callback_job_create((callback_job_cb_t)run, this, NULL, NULL));
88
89 return &this->public.plugin;
90 }
91