/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
#include <aul.h>
#include <aul_app_com.h>
#include <dlog.h>
+#include <appcore_multiwindow_base.h>
#include "widget_app.h"
#include "widget-log.h"
#endif
#define LOG_TAG "CAPI_WIDGET_APPLICATION"
+extern char *_viewer_endpoint;
+static char *__class_id;
-static char *viewer_endpoint = NULL;
-static GList *contexts = NULL;
+static void __inst_cb(const char *class_id, const char *id,
+ appcore_multiwindow_base_instance_h cxt, void *data)
+{
+ if (!__class_id)
+ __class_id = strdup(class_id);
+}
-EXPORT_API int widget_app_restart()
+EXPORT_API int widget_app_restart(void)
{
int ret;
int status = AUL_WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST;
bundle *kb;
- widget_context_s *wc;
- char *classid;
- if (contexts == NULL) {
- _E("no widget");
- return WIDGET_ERROR_IO_ERROR;
- }
- wc = (widget_context_s *)contexts->data;
- classid = wc->provider->classid;
- _D("restart widget classid : %s", classid);
+ appcore_multiwindow_base_instance_foreach_full(__inst_cb, NULL);
kb = bundle_create();
- bundle_add_str(kb, AUL_K_WIDGET_ID, classid);
+ bundle_add_str(kb, AUL_K_WIDGET_ID, __class_id);
bundle_add_byte(kb, AUL_K_WIDGET_STATUS, &status, sizeof(int));
- ret = aul_app_com_send(viewer_endpoint, kb);
+ ret = aul_app_com_send(_viewer_endpoint, kb);
bundle_free(kb);
+ if (__class_id) {
+ free(__class_id);
+ __class_id = NULL;
+ }
+
if (ret != AUL_R_OK) {
_E("failed to kill app");
return WIDGET_ERROR_IO_ERROR;
return WIDGET_ERROR_NONE;
}
-GList *_widget_app_get_contexts()
-{
- return contexts;
-}
-
-int _widget_app_add_context(widget_context_s *wc)
-{
- contexts = g_list_append(contexts, wc);
- return WIDGET_ERROR_NONE;
-}
-
-int _widget_app_remove_context(widget_context_s *wc)
-{
- contexts = g_list_remove(contexts, wc);
- return WIDGET_ERROR_NONE;
-}
-
-int _widget_app_set_viewer_endpoint(char *endpoint)
-{
- if (endpoint == NULL)
- return WIDGET_ERROR_INVALID_PARAMETER;
-
- viewer_endpoint = strdup(endpoint);
- if (viewer_endpoint == NULL)
- return WIDGET_ERROR_OUT_OF_MEMORY;
-
- return WIDGET_ERROR_NONE;
-}
-
-char *_widget_app_get_viewer_endpoint()
-{
- return viewer_endpoint;
-}
-
-int _widget_app_free_viewer_endpoint()
-{
- if (viewer_endpoint)
- free(viewer_endpoint);
-
- return WIDGET_ERROR_NONE;
-}