gisi: move g_isi_modem_by_name to separate file

This fixes build warnings that resulted from conflicts between
linux/if.h and net/if.h.
This commit is contained in:
Aki Niemi 2010-04-21 10:47:16 +03:00
parent 3dc106c627
commit 22103491a4
4 changed files with 68 additions and 32 deletions

View File

@ -41,11 +41,15 @@ builtin_cflags =
gdbus_sources = gdbus/gdbus.h gdbus/mainloop.c gdbus/object.c gdbus/watch.c
gisi_sources = gisi/phonet.h gisi/modem.h gisi/netlink.h gisi/netlink.c \
gisi/socket.h gisi/socket.c gisi/client.h gisi/client.c \
gisi/server.h gisi/server.c \
gisi/pep.h gisi/pep.c gisi/pipe.h gisi/pipe.c gisi/iter.h \
gisi/iter.c gisi/verify.c
gisi_sources = gisi/modem.h gisi/modem.c \
gisi/netlink.h gisi/netlink.c \
gisi/socket.h gisi/socket.c \
gisi/client.h gisi/client.c \
gisi/server.h gisi/server.c \
gisi/pep.h gisi/pep.c \
gisi/pipe.h gisi/pipe.c \
gisi/iter.h gisi/iter.c \
gisi/verify.c gisi/phonet.h
gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \
gatchat/gatresult.h gatchat/gatresult.c \

36
gisi/modem.c Normal file
View File

@ -0,0 +1,36 @@
/**
* Copyright (C) 2010 Nokia 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 <errno.h>
#include <net/if.h>
#include "modem.h"
GIsiModem *g_isi_modem_by_name(char const *name)
{
unsigned index = if_nametoindex(name);
if (errno == 0)
errno = ENODEV;
return (GIsiModem *)(void *)(uintptr_t)index;
}

View File

@ -1,5 +1,7 @@
/**
* Copyright (C) 2009 Nokia Corporation. All rights reserved.
/*
* This file is part of oFono - Open Source Telephony
*
* Copyright (C) 2010 Nokia 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
@ -15,11 +17,19 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef GISI_MODEM_H
#define GISI_MODEM_H
#ifndef __GISI_MODEM_H
#define __GISI_MODEM_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*GIsiDebugFunc) (const void *restrict data, size_t len,
void *opaque);
typedef struct _GIsiModem GIsiModem;
static inline unsigned g_isi_modem_index(GIsiModem *m)
@ -27,9 +37,10 @@ static inline unsigned g_isi_modem_index(GIsiModem *m)
return (uintptr_t)m;
}
GIsiModem *g_isi_modem_by_name(char const *name);
typedef void (*GIsiDebugFunc) (const void *restrict data, size_t len,
void *opaque);
GIsiModem *g_isi_modem_by_name(const char *name);
#ifdef __cplusplus
}
#endif
#endif /* __GISI_MODEM_H */

View File

@ -76,21 +76,6 @@ struct _GPhonetNetlink {
unsigned interface;
};
/* if_nametoindex is in #include <net/if.h>,
but it is not compatible with <linux/if.h> */
extern unsigned if_nametoindex (char const *name);
GIsiModem *g_isi_modem_by_name(char const *name)
{
unsigned index = if_nametoindex(name);
if (errno == 0)
errno = ENODEV;
return (GIsiModem *)(void *)(uintptr_t)index;
}
static inline GIsiModem *make_modem(unsigned idx)
{
return (void *)(uintptr_t)idx;
@ -113,15 +98,15 @@ GPhonetNetlink *g_pn_netlink_by_modem(GIsiModem *idx)
return NULL;
}
GPhonetNetlink *g_pn_netlink_by_name(char const *ifname)
GPhonetNetlink *g_pn_netlink_by_name(const char *ifname)
{
if (ifname == NULL) {
return g_pn_netlink_by_modem(make_modem(0));
} else {
unsigned index = if_nametoindex(ifname);
if (index == 0)
GIsiModem *idx = g_isi_modem_by_name(ifname);
if (!idx)
return NULL;
return g_pn_netlink_by_modem(make_modem(index));
return g_pn_netlink_by_modem(idx);
}
}