Begin to place the channel code in a dedicated file

This commit is contained in:
Pierre Pronchery 2015-12-28 17:19:57 +01:00
parent 8557486e27
commit cc472bb6de
8 changed files with 146 additions and 74 deletions

View File

@ -38,6 +38,7 @@
#include <glib.h>
#include <System.h>
#include <Phone/modem.h>
#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);
}

View File

@ -0,0 +1,42 @@
/* $Id$ */
/* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
/* 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 <http://www.gnu.org/licenses/>. */
#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;
}

View File

@ -0,0 +1,91 @@
/* $Id$ */
/* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
/* 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 <http://www.gnu.org/licenses/>. */
#ifndef PHONE_MODEM_HAYES_CHANNEL_H
# define PHONE_MODEM_HAYES_CHANNEL_H
# include <sys/types.h>
# include <stdio.h>
# include <Phone/modem.h>
# include <glib.h>
/* 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 */

View File

@ -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

View File

@ -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"

View File

@ -20,6 +20,7 @@
#include <string.h>
#include <time.h>
#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"

View File

@ -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"

View File

@ -17,6 +17,7 @@
#include <unistd.h>
#include <stdio.h>
#include "../src/modems/hayes/channel.c"
#include "../src/modems/hayes/command.c"
#include "../src/modems/hayes/quirks.c"
#include "../src/modems/hayes.c"