Questing about the use of libmm
Troels Olesen
to at movis.dk
Mon Feb 8 10:35:35 UTC 2016
Here is an example code of my problem with MMManager* memory leak.
---------------
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
// HACK: 'class' is a reserved keyword in C++
#ifdef __cplusplus
extern "C" {
# define class modemClass
#endif
#include <libmm-glib.h>
#if __cplusplus
# undef class
} //Extern C
#endif
using namespace std;
void GetModemState()
{
GError *error = NULL;
// Get Gdbus Connection
GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM,
NULL, &error);
if(!connection)
{
g_warning("GetModemState : Failed to get gdbus connection");
g_error_free(error);
}
// Get MMModemManager
MMManager *manager = mm_manager_new_sync(connection,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, NULL, &error);
if(!manager)
{
g_warning("GetModemState : Failed to get MMManager");
g_error_free(error);
}
// Get list of Modems.
GList *modem_list =
g_dbus_object_manager_get_objects(G_DBUS_OBJECT_MANAGER(manager));
// Select first modem. and set it as MMObject.
MMObject* object = MM_OBJECT(modem_list->data);
// Get MMModem. (peek)
MMModem *modem = mm_object_peek_modem(object);
// Get MMModemState
MMModemState modem_state = mm_modem_get_state(modem);
cout << "Modem state is : " << modem_state << endl;
// Free glist modems.
g_list_free_full(modem_list, (GDestroyNotify)g_object_unref);
// Clear pointer referances.
g_object_unref(manager);
g_object_unref(connection);
}
int main()
{
gboolean run = true;
int count = 0;
while(run)
{
GetModemState();
cout << "count : " << count << endl;
if(count > 100000)
run = false;
count++;
//sleep(1);
}
return 0;
}
-------------
When this code is run, it leaks about 0,6kb memery pr. loop.
Den 08-02-2016 kl. 09:59 skrev Troels Olesen:
> Hi ModemManager developers.
>
> I have some questions about the how to use the "libmm" library, in an
> modem handler application.
>
> I have read your API wiki, at
> "http://www.freedesktop.org/software/ModemManager/libmm-glib/latest/",
> and i have managed to make an application that like mmcli can get
> information from the ModemManager daemon.
>
> But i have some problems getting updated information from the MM
> objects i create.
>
> The way i understand the MM object structure is that the MMManager*
> object gives a list of MMObject*, and from the MMObject* it is
> possible to get MMModem*, MMModemLocation* and MMModem3gpp* objects
> witch gives the information that i am searching for.
>
> It is also possible for me to generate these pointer objects, but i
> have some problems getting them updated, in such a manner that i can
> run a loop application to check status of the modem.
>
> Especially the function "mm_modem_get_state(MMModem*)", does not seem
> to update its information, when i run it without resetting all above
> pointer objects. it this the correct behavior for this function?
>
> Should i consider all MM object pointers as a snapshot frozen in time,
> from when the MMManager* or MMObject* was generated?
>
> Another problem i have, is understanding the correct clearing/unref
> procedure for MMManager*, it does not say in the API wiki, if it
> should be cleared with g_object_unref or NULL, or some other way. an
> no matter how i try to clear this object it seams that i end up with a
> memory leak or a double free pointer error.
>
> I hope you can help me.
> Thanks
>
> Troels Olesen.
>
> _______________________________________________
> ModemManager-devel mailing list
> ModemManager-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel
More information about the ModemManager-devel
mailing list