Hey,
>
> I'm writing a simple C code to interface to MM to be able to read some
> stats. I'm following the mmcli examples as was suggested earlier.
>
> All I'm currently reading is mm_modem_get_manufacturer (ctx->modem); so
> nothing complex.
>
> I have the following headers:
>
> #include "config.h"
>
This config.h is only needed if building from within the MM source
tree (unless you have your own config.h).
> #include <stdio.h>
> #include <stdlib.h>
> #include <locale.h>
>
> #define _LIBMM_INSIDE_MMCLI
>
You must not define this symbol for external programs. This is a
symbol that should only be included within mmcli sources.
> #include <glib.h>
> #include <gio/gio.h>
>
> #include <libmm-glib/libmm-glib.h>
> #include "../libmm-glib/mm-modem.h"
>
You should only #include <libmm-glib.h>.
> #include "mmcli.h"
> #include "mmcli-common.h"
>
This should only be needed from within mmcli sources.
> I have a simple Makefile for it too:
> CC=gcc
>
> top_build_prefix = ../
> top_builddir = ..
> top_srcdir = ..
> MMCLI_CFLAGS = -pthread -I/usr/include/glib-2.0
> -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/gio-unix-2.0/
> CFLAGS= \
> $(MMCLI_CFLAGS) \
> -I$(top_srcdir) \
> -I$(top_srcdir)/include \
> -I$(top_builddir)/include \
> -I$(top_srcdir)/libmm-glib \
> -I${top_srcdir}/libmm-glib/generated \
> -I${top_builddir}/libmm-glib/generated
>
> MMCLI_LIBS = -lgio-2.0 -lgobject-2.0 -lglib-2.0
>
> LDFLAGS=$(MMCLI_LIBS) \
> $(top_builddir)/libmm-glib/libmm-glib.la
>
>
>
> all: ali
>
> build: ali.o
> $(CC) ali.o -o ali
>
> ali.o: ali.c
> $(CC) $(CFLAGS) $(LDFLAGS) $(MMCLI_LIBS) ali.c
>
> clean:
> rm *o ali
>
libmm-glib uses pkg-config, so you can use that better instead of
hand-coding the CFLAGS and LDFLAGS. This also allows you to compile a
program from out of the ModemManager source tree, which you should.
See example below.
>
> The code is placed in cli/ alongside mmcli source codes.
>
Yeah no need to do that.
> When I build it with the makefile I get the following error:
> root@beaglebone:~/MM/ModemManager-1.4.12/cli# make -f aliMake
> gcc -pthread -I/usr/include/glib-2.0
> -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/gio-unix-2.0/
> -I.. -I../include -I../include -I../libmm-glib -I../libmm-glib/generated
> -I../libmm-glib/generated -lgio-2.0 -lgobject-2.0 -lglib-2.0
> ../libmm-glib/libmm-glib.la -lgio-2.0 -lgobject-2.0 -lglib-2.0 ali.c
> ../libmm-glib/libmm-glib.la: file not recognized: File format not recognized
> collect2: ld returned 1 exit status
> make: *** [ali.o] Error 1
>
>
> But when I make mmcli it compiles fine.
>
> What am I doing wrong/missing?
Don't build within MM sources, you can compile your external program
easily e.g. like this:
$ gcc -o test-mm `pkg-config --cflags --libs mm-glib` test-mm.c
See attached tester program for an out-of-tree example.
--
Aleksander
https://aleksander.es
/* Compile with:
*
* $ gcc -o test-mm `pkg-config --cflags --libs mm-glib` test-mm.c
*/
#include <libmm-glib.h>
int main (int argc, const char **argv)
{
GDBusConnection *connection;
MMManager *manager;
gchar *name_owner;
GError *error = NULL;
GList *modems;
/* Setup dbus connection to use */
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!connection) {
g_printerr ("error: couldn't get bus: %s\n",
error ? error->message : "unknown error");
return -1;
}
manager = mm_manager_new_sync (connection,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START,
NULL,
&error);
if (!manager) {
g_printerr ("error: couldn't create manager: %s\n",
error ? error->message : "unknown error");
g_object_unref (connection);
return -2;
}
name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
if (!name_owner) {
g_printerr ("error: couldn't find the ModemManager process in the bus\n");
g_object_unref (connection);
g_object_unref (manager);
return -3;
}
g_print ("ModemManager process found at '%s'\n", name_owner);
g_free (name_owner);
modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager));
g_print ("\n");
if (!modems)
g_print ("No modems were found\n");
else {
GList *l;
g_print ("Found %u modems:\n", g_list_length (modems));
for (l = modems; l; l = g_list_next (l)) {
MMObject *modem;
const gchar *manufacturer, *model;
modem = MM_OBJECT (l->data);
manufacturer = mm_modem_get_manufacturer (mm_object_peek_modem (modem));
model = mm_modem_get_model (mm_object_peek_modem (modem));
g_print ("\t%s [%s] %s\n",
mm_object_get_path (modem),
manufacturer ? manufacturer : "unknown",
model ? model : "unknown");
}
g_list_free_full (modems, (GDestroyNotify) g_object_unref);
}
g_print ("\n");
g_object_unref (connection);
g_object_unref (manager);
return 0;
}
_______________________________________________
ModemManager-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel