diff options
author | Denis Kenzior <denkenz@gmail.com> | 2011-02-09 23:22:43 -0600 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2011-02-10 00:34:47 -0600 |
commit | 09bb5f7554eee7456beb63b54e577e472fd3c3d0 (patch) | |
tree | 64de72a903a49ff33094bfc48756e3f9b3b33475 /src/emulator.c | |
parent | 6352e799efb0495c741a6a03f9bff3922af4b995 (diff) | |
download | ofono-09bb5f7554eee7456beb63b54e577e472fd3c3d0.tar.bz2 |
emulator: Add basic emulator skeleton
Diffstat (limited to 'src/emulator.c')
-rw-r--r-- | src/emulator.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/emulator.c b/src/emulator.c new file mode 100644 index 00000000..c49283de --- /dev/null +++ b/src/emulator.c @@ -0,0 +1,112 @@ +/* + * + * oFono - Open Source Telephony + * + * Copyright (C) 2008-2011 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib.h> + +#include "ofono.h" +#include "gatserver.h" + +struct ofono_emulator { + struct ofono_atom *atom; + GAtServer *server; +}; + +static void emulator_debug(const char *str, void *data) +{ + ofono_info("%s: %s\n", (char *)data, str); +} + +static void emulator_disconnect(gpointer user_data) +{ + struct ofono_emulator *em = user_data; + + DBG("%p", em); + + ofono_emulator_remove(em); +} + +static void emulator_unregister(struct ofono_atom *atom) +{ + struct ofono_emulator *em = __ofono_atom_get_data(atom); + + DBG("%p", em); + + g_at_server_unref(em->server); + em->server = NULL; +} + +void ofono_emulator_register(struct ofono_emulator *em, int fd) +{ + GIOChannel *io; + + DBG("%p, %d", em, fd); + + if (fd < 0) + return; + + io = g_io_channel_unix_new(fd); + + em->server = g_at_server_new(io); + if (em->server == NULL) + return; + + g_at_server_set_debug(em->server, emulator_debug, "Server"); + g_at_server_set_disconnect_function(em->server, + emulator_disconnect, em); + + __ofono_atom_register(em->atom, emulator_unregister); +} + +static void emulator_remove(struct ofono_atom *atom) +{ + struct ofono_emulator *em = __ofono_atom_get_data(atom); + + DBG("atom: %p", atom); + + g_free(em); +} + +struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem, + enum ofono_emulator_type type) +{ + struct ofono_emulator *em; + + DBG("modem: %p, type: %d", modem, type); + + em = g_try_new0(struct ofono_emulator, 1); + + if (em == NULL) + return NULL; + + em->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_EMULATOR_DUN, + emulator_remove, em); + + return em; +} + +void ofono_emulator_remove(struct ofono_emulator *em) +{ + __ofono_atom_free(em->atom); +} |