Implement g_at_ppp_set_debug support

This commit is contained in:
Marcel Holtmann 2010-04-01 13:11:11 -07:00
parent dc55d14e9c
commit ef82241deb
5 changed files with 34 additions and 15 deletions

View File

@ -44,13 +44,13 @@ void g_at_ppp_open(GAtPPP *ppp)
} }
void g_at_ppp_set_credentials(GAtPPP *ppp, const char *username, void g_at_ppp_set_credentials(GAtPPP *ppp, const char *username,
const char *passwd) const char *passwd)
{ {
auth_set_credentials(ppp->auth, username, passwd); auth_set_credentials(ppp->auth, username, passwd);
} }
void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc func, void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc func,
gpointer user_data) gpointer user_data)
{ {
if (func == NULL) if (func == NULL)
return; return;
@ -60,7 +60,7 @@ void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc func,
} }
void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc func, void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc func,
gpointer user_data) gpointer user_data)
{ {
if (func == NULL) if (func == NULL)
return; return;
@ -69,6 +69,15 @@ void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc func,
ppp->disconnect_data = user_data; ppp->disconnect_data = user_data;
} }
void g_at_ppp_set_debug(GAtPPP *ppp, GAtDebugFunc func, gpointer user_data)
{
if (ppp == NULL)
return;
ppp->debugf = func;
ppp->debug_data = user_data;
}
void g_at_ppp_shutdown(GAtPPP *ppp) void g_at_ppp_shutdown(GAtPPP *ppp)
{ {
/* close the ppp link */ /* close the ppp link */

View File

@ -47,6 +47,7 @@ void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc callback,
gpointer user_data); gpointer user_data);
void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc func, void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc func,
gpointer user_data); gpointer user_data);
void g_at_ppp_set_debug(GAtPPP *ppp, GAtDebugFunc func, gpointer user_data);
void g_at_ppp_shutdown(GAtPPP *ppp); void g_at_ppp_shutdown(GAtPPP *ppp);
void g_at_ppp_ref(GAtPPP *ppp); void g_at_ppp_ref(GAtPPP *ppp);
void g_at_ppp_unref(GAtPPP *ppp); void g_at_ppp_unref(GAtPPP *ppp);

View File

@ -71,7 +71,7 @@ static int oldmode = 0;
static void gsmdial_debug(const char *str, void *data) static void gsmdial_debug(const char *str, void *data)
{ {
g_print("%s: %s\n", (const char *)data, str); g_print("%s: %s\n", (const char *) data, str);
} }
static gboolean quit_eventloop(gpointer user_data) static gboolean quit_eventloop(gpointer user_data)
@ -269,8 +269,9 @@ static void connect_cb(gboolean ok, GAtResult *result, gpointer user_data)
g_print("Unable to create PPP object\n"); g_print("Unable to create PPP object\n");
exit(1); exit(1);
} }
g_at_ppp_set_credentials(ppp, option_username, g_at_ppp_set_debug(ppp, gsmdial_debug, "PPP");
option_password);
g_at_ppp_set_credentials(ppp, option_username, option_password);
/* set connect and disconnect callbacks */ /* set connect and disconnect callbacks */
g_at_ppp_set_connect_function(ppp, ppp_connect, NULL); g_at_ppp_set_connect_function(ppp, ppp_connect, NULL);

View File

@ -137,6 +137,8 @@ struct _GAtPPP {
GAtDisconnectFunc disconnect_cb; GAtDisconnectFunc disconnect_cb;
gpointer disconnect_data; gpointer disconnect_data;
gint modem_watch; gint modem_watch;
GAtDebugFunc debugf;
gpointer debug_data;
}; };
gboolean ppp_cb(GIOChannel *channel, GIOCondition cond, gpointer data); gboolean ppp_cb(GIOChannel *channel, GIOCondition cond, gpointer data);

View File

@ -34,19 +34,25 @@
#include "gatppp.h" #include "gatppp.h"
#include "ppp.h" #include "ppp.h"
#define DEBUG
#ifdef DEBUG
static const char *pppcp_state_strings[] = static const char *pppcp_state_strings[] =
{"INITIAL", "STARTING", "CLOSED", "STOPPED", "CLOSING", "STOPPING", {"INITIAL", "STARTING", "CLOSED", "STOPPED", "CLOSING", "STOPPING",
"REQSENT", "ACKRCVD", "ACKSENT", "OPENED" }; "REQSENT", "ACKRCVD", "ACKSENT", "OPENED" };
#define pppcp_trace(p) do { \ static void pppcp_debug(struct pppcp_data *p, const char *func)
g_print("%s: %s: current state %d:%s\n", p->prefix, __FUNCTION__, \ {
p->state, pppcp_state_strings[p->state]); \ GAtPPP *ppp = p->ppp;
} while (0) char *str;
#else
#define pppcp_trace(p) do { } while (0) if (!ppp || !ppp->debugf)
#endif return;
str = g_strdup_printf("%s: %s: current state %d:%s",
p->prefix, func, p->state, pppcp_state_strings[p->state]);
ppp->debugf(str, ppp->debug_data);
g_free(str);
}
#define pppcp_trace(p) pppcp_debug(p, __FUNCTION__)
#define pppcp_to_ppp_packet(p) \ #define pppcp_to_ppp_packet(p) \
(((guint8 *) p) - PPP_HEADROOM) (((guint8 *) p) - PPP_HEADROOM)