So I recently tried to try out GeoClue for one of my Raspberry Pi projects, but I got stuck on using gclue-simple(). Running gclue_simple_new seemed to be fine, but when I was trying to pick up the pointer with gclue_simple_new_finish(), the program gives me a runtime error:
(process:37607): GLib-GIO-CRITICAL **: 16:26:33.873: g_async_result_get_source_object: assertion 'G_IS_ASYNC_RESULT (res)' failed
(process:37607): GLib-GIO-CRITICAL **: 16:26:33.873: g_async_initable_init_finish: assertion 'G_IS_ASYNC_INITABLE (initable)' failed
(process:37607): GLib-GObject-CRITICAL **: 16:26:33.873: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
The code for the program is here:
#include <cstdlib>
#include <iostream>
#include <gclue-simple.h>
void geoclue_callback (GObject* srcObj, GAsyncResult* result, void* userData);
int main(){
std::cout << "Program started." << std::endl;
const char* DESKTOP_ID = "desktop1";
GClueAccuracyLevel accuracy = GCLUE_ACCURACY_LEVEL_CITY;
GCancellable* cancellablePtr = NULL;
GAsyncReadyCallback callback = geoclue_callback;
//gpointer is like void pointer.
gpointer usrDataPtr;
std::cout << "Variables declared." << std::endl;
gclue_simple_new(
DESKTOP_ID,
accuracy,
cancellablePtr,
callback,
usrDataPtr
);
std::cout << "geoclue service started." << std::endl;
GClueSimple* gclueServicePtr;
GAsyncResult* rstPtr;
GError** errsPtr;
//This part here causes runtime error.
gclueServicePtr = gclue_simple_new_finish(rstPtr, errsPtr);
}
void geoclue_callback (GObject* srcObj, GAsyncResult* result, void* userData) {
//Callback function for when Geoclue comes up with something
std::cout << "Results Ready." << std::endl;
}
I've only just gotten into geoclue and I have no previous experience with anything related to gtk or the GNOME project, so I'm probably missing something obvious.
Thanks!
The
callbackis not to tell you that some results are ready, it’s to tell you that yourGClueSimple*object has been created. You need to callgclue_simple_new_finish()from insidecallback, not before. And you need to pass theGAsyncResult *resultinto it, plus a pointer to aGError *error = NULLinitialised error.gclue_simple_new_finish()may returnNULL(and aGErrorobject in the error pointer you gave it) if initialisation failed.