From cc472bb6de13bec3add04c67b9477d36f3ad835a Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Mon, 28 Dec 2015 17:19:57 +0100 Subject: [PATCH] Begin to place the channel code in a dedicated file --- src/modems/hayes.c | 74 ++----------------------------- src/modems/hayes/channel.c | 42 ++++++++++++++++++ src/modems/hayes/channel.h | 91 ++++++++++++++++++++++++++++++++++++++ src/modems/project.conf | 9 ++-- tests/hayes.c | 1 + tests/pdu.c | 1 + tests/ussd.c | 1 + tools/pdu.c | 1 + 8 files changed, 146 insertions(+), 74 deletions(-) create mode 100644 src/modems/hayes/channel.c create mode 100644 src/modems/hayes/channel.h diff --git a/src/modems/hayes.c b/src/modems/hayes.c index 721d180..9f9be05 100644 --- a/src/modems/hayes.c +++ b/src/modems/hayes.c @@ -38,6 +38,7 @@ #include #include #include +#include "hayes/channel.h" #include "hayes/command.h" #include "hayes/quirks.h" #include "hayes.h" @@ -49,62 +50,6 @@ /* Hayes */ /* private */ /* types */ -typedef enum _HayesChannelMode -{ - HAYES_MODE_INIT = 0, - HAYES_MODE_COMMAND, - HAYES_MODE_DATA -} HayesChannelMode; - -typedef struct _HayesChannel -{ - ModemPlugin * hayes; - - unsigned int quirks; - - guint timeout; - guint authenticate_count; - guint authenticate_source; - - GIOChannel * channel; - char * rd_buf; - size_t rd_buf_cnt; - guint rd_source; - char * wr_buf; - size_t wr_buf_cnt; - guint wr_source; - GIOChannel * rd_ppp_channel; - guint rd_ppp_source; - GIOChannel * wr_ppp_channel; - guint wr_ppp_source; - - /* logging */ - FILE * fp; - - /* queue */ - HayesChannelMode mode; - GSList * queue; - GSList * queue_timeout; - - /* events */ - ModemEvent events[MODEM_EVENT_TYPE_COUNT]; - char * authentication_name; - char * authentication_error; - char * call_number; - char * contact_name; - char * contact_number; - char * gprs_username; - char * gprs_password; - char * message_number; - char * model_identity; - char * model_name; - char * model_serial; - char * model_vendor; - char * model_version; - char * registration_media; - char * registration_operator; -} HayesChannel; - typedef struct _ModemPlugin { ModemPluginHelper * helper; @@ -595,8 +540,6 @@ ModemPluginDefinition plugin = /* private */ /* plug-in */ /* functions */ -static void _init_channel(Hayes * hayes, HayesChannel * channel); - static ModemPlugin * _hayes_init(ModemPluginHelper * helper) { Hayes * hayes; @@ -605,27 +548,16 @@ static ModemPlugin * _hayes_init(ModemPluginHelper * helper) return NULL; memset(hayes, 0, sizeof(*hayes)); hayes->helper = helper; - _init_channel(hayes, &hayes->channel); + hayeschannel_init(&hayes->channel, hayes); return hayes; } -static void _init_channel(Hayes * hayes, HayesChannel * channel) -{ - size_t i; - - channel->hayes = hayes; - channel->mode = HAYES_MODE_INIT; - for(i = 0; i < sizeof(channel->events) / sizeof(*channel->events); i++) - channel->events[i].type = i; - channel->events[MODEM_EVENT_TYPE_REGISTRATION].registration.signal - = 0.0 / 0.0; -} - /* hayes_destroy */ static void _hayes_destroy(Hayes * hayes) { _hayes_stop(hayes); + hayeschannel_destroy(&hayes->channel); object_delete(hayes); } diff --git a/src/modems/hayes/channel.c b/src/modems/hayes/channel.c new file mode 100644 index 0000000..c4211ca --- /dev/null +++ b/src/modems/hayes/channel.c @@ -0,0 +1,42 @@ +/* $Id$ */ +/* Copyright (c) 2015 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Phone */ +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * 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, see . */ + + + +#include "channel.h" + + +/* HayesChannel */ +/* public */ +/* functions */ +/* hayeschannel_init */ +void hayeschannel_init(HayesChannel * channel, ModemPlugin * modem) +{ + size_t i; + + channel->hayes = modem; + channel->mode = HAYES_MODE_INIT; + for(i = 0; i < sizeof(channel->events) / sizeof(*channel->events); i++) + channel->events[i].type = i; + channel->events[MODEM_EVENT_TYPE_REGISTRATION].registration.signal + = 0.0 / 0.0; +} + + +/* hayeschannel_destroy */ +void hayeschannel_destroy(HayesChannel * channel) +{ + (void) channel; +} diff --git a/src/modems/hayes/channel.h b/src/modems/hayes/channel.h new file mode 100644 index 0000000..e4c8015 --- /dev/null +++ b/src/modems/hayes/channel.h @@ -0,0 +1,91 @@ +/* $Id$ */ +/* Copyright (c) 2015 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Phone */ +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * 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, see . */ + + + +#ifndef PHONE_MODEM_HAYES_CHANNEL_H +# define PHONE_MODEM_HAYES_CHANNEL_H + +# include +# include +# include +# include + + +/* HayesChannel */ +/* public */ +/* types */ +typedef enum _HayesChannelMode +{ + HAYES_MODE_INIT = 0, + HAYES_MODE_COMMAND, + HAYES_MODE_DATA +} HayesChannelMode; + +typedef struct _HayesChannel +{ + ModemPlugin * hayes; + + unsigned int quirks; + + guint timeout; + guint authenticate_count; + guint authenticate_source; + + GIOChannel * channel; + char * rd_buf; + size_t rd_buf_cnt; + guint rd_source; + char * wr_buf; + size_t wr_buf_cnt; + guint wr_source; + GIOChannel * rd_ppp_channel; + guint rd_ppp_source; + GIOChannel * wr_ppp_channel; + guint wr_ppp_source; + + /* logging */ + FILE * fp; + + /* queue */ + HayesChannelMode mode; + GSList * queue; + GSList * queue_timeout; + + /* events */ + ModemEvent events[MODEM_EVENT_TYPE_COUNT]; + char * authentication_name; + char * authentication_error; + char * call_number; + char * contact_name; + char * contact_number; + char * gprs_username; + char * gprs_password; + char * message_number; + char * model_identity; + char * model_name; + char * model_serial; + char * model_vendor; + char * model_version; + char * registration_media; + char * registration_operator; +} HayesChannel; + + +/* functions */ +void hayeschannel_init(HayesChannel * channel, ModemPlugin * modem); +void hayeschannel_destroy(HayesChannel * channel); + +#endif /* PHONE_MODEM_HAYES_CHANNEL_H */ diff --git a/src/modems/project.conf b/src/modems/project.conf index 0ba1a22..b1a38e6 100644 --- a/src/modems/project.conf +++ b/src/modems/project.conf @@ -5,7 +5,7 @@ cflags_force=`pkg-config --cflags glib-2.0` -fPIC cflags=-W -Wall -g -O2 -pedantic -D_FORTIFY_SOURCE=2 -fstack-protector-all ldflags_force=`pkg-config --libs glib-2.0` includes=hayes.h -dist=Makefile,hayes/command.h,hayes/quirks.h,osmocom.c +dist=Makefile,hayes/channel.h,hayes/command.h,hayes/quirks.h,osmocom.c [debug] type=plugin @@ -21,13 +21,16 @@ depends=../../config.h [hayes] type=plugin -sources=hayes/command.c,hayes/quirks.c,hayes.c +sources=hayes/channel.c,hayes/command.c,hayes/quirks.c,hayes.c cflags=`pkg-config --cflags libSystem` ldflags=`pkg-config --libs libSystem` install=$(LIBDIR)/Phone/modem [hayes.c] -depends=hayes/command.h,hayes/quirks.h,hayes.h +depends=hayes/channel.h,hayes/command.h,hayes/quirks.h,hayes.h + +[hayes/channel.c] +depends=hayes/channel.h [hayes/command.c] depends=hayes/command.h diff --git a/tests/hayes.c b/tests/hayes.c index 9cfbe56..28121cf 100644 --- a/tests/hayes.c +++ b/tests/hayes.c @@ -15,6 +15,7 @@ +#include "../src/modems/hayes/channel.c" #include "../src/modems/hayes/command.c" #include "../src/modems/hayes/quirks.c" #include "../src/modems/hayes.c" diff --git a/tests/pdu.c b/tests/pdu.c index 1ec8bd5..bbe2fea 100644 --- a/tests/pdu.c +++ b/tests/pdu.c @@ -20,6 +20,7 @@ #include #include #include "Phone/modem.h" +#include "../src/modems/hayes/channel.c" #include "../src/modems/hayes/command.c" #include "../src/modems/hayes/quirks.c" #include "../src/modems/hayes.c" diff --git a/tests/ussd.c b/tests/ussd.c index 8b80d53..f77cab6 100644 --- a/tests/ussd.c +++ b/tests/ussd.c @@ -15,6 +15,7 @@ +#include "../src/modems/hayes/channel.c" #include "../src/modems/hayes/command.c" #include "../src/modems/hayes/quirks.c" #include "../src/modems/hayes.c" diff --git a/tools/pdu.c b/tools/pdu.c index 881437e..9a6b418 100644 --- a/tools/pdu.c +++ b/tools/pdu.c @@ -17,6 +17,7 @@ #include #include +#include "../src/modems/hayes/channel.c" #include "../src/modems/hayes/command.c" #include "../src/modems/hayes/quirks.c" #include "../src/modems/hayes.c"