if (argumentCount > 5) {
cbP->errorCB = validator.toFunction(5, true);
JSValueProtect(cbP->context, cbP->errorCB);
+ } else {
+ cbP->errorCB = NULL;
}
MediaServerPtr server(privateObject->getObject());
if (argumentCount > 6) {
cbP->errorCB = validator.toFunction(6, true);
JSValueProtect(cbP->context, cbP->errorCB);
+ } else {
+ cbP->errorCB = NULL;
}
MediaServerPtr server(privateObject->getObject());
/* forward declaration for browse / find finishing callback */
static void browseFindCallback(GVariant * out_Children, BrowseFindCB * callback);
+static void browseFindErrorCallback(GError * error, BrowseFindCB * callback);
/*
* Callback for find on UPnPContainer2 proxy
&gerror /* error */
)) {
LoggerD("findCallback success");
+ /* Prepare results for Javascript callback */
+ browseFindCallback(out_Children, callback);
} else {
LoggerE(gerror->message);
+ browseFindErrorCallback(gerror, callback) ;
g_error_free(gerror);
- return;
}
-
- /* Prepare results for Javascript callback */
- browseFindCallback(out_Children, callback);
}
&gerror /* error */
)) {
LoggerD("browseCallback success");
+ /* Prepare results for Javascript callback */
+ browseFindCallback(out_Children, callback);
} else {
LoggerE(gerror->message);
+ browseFindErrorCallback(gerror, callback) ;
g_error_free(gerror);
- return;
}
-
- /* Prepare results for Javascript callback */
- browseFindCallback(out_Children, callback);
}
static void browseFindCallback(GVariant * out_Children, BrowseFindCB * callback) {
g_object_unref(callback->cntProxy);
}
+static void browseFindErrorCallback(GError * error, BrowseFindCB * callback) {
+ /* convert children to Javascript array */
+ gsize size;
+ gchar * gStr = error->message;
+ LoggerE(gStr);
+ if(callback->errorCB) {
+ JSStringRef jsStr = JSStringCreateWithUTF8CString(gStr);
+ LoggerD("Converting string to JSON");
+ JSValueRef jsArray = JSValueMakeFromJSONString(callback->context, jsStr);
+ const JSValueRef arguments[1] = { jsArray };
+ LoggerD("Triggering JS callback");
+ /* Trigger callback */
+ JSObjectCallAsFunction(callback->context,
+ callback->errorCB,
+ NULL,
+ 1,
+ arguments,
+ NULL);
+ /* free upn_pcontainer2 proxy */
+ g_object_unref(callback->cntProxy);
+ }
+}