2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file BoxDaemonImpl.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
20 #include <sys/types.h>
27 #include <livebox-service.h>
28 #include <Core/Util/Log.h>
29 #include <Plugin/IBoxPluginConnector.h>
30 #include <Plugin/BoxPluginConnector.h>
31 #include <API/web_provider_livebox_info.h>
32 #include "BoxDaemonUtil.h"
33 #include "BoxDaemonImpl.h"
35 #define MASTER_PROVIDER_PING_TIME 120.0f
37 BoxDaemonImpl::BoxDaemonImpl()
38 : m_pluginConnector(BoxPluginConnector::create())
42 BoxDaemonImpl::~BoxDaemonImpl()
46 bool BoxDaemonImpl::start(std::string& name)
50 // initialize existing plugins for web livebox
51 if (!m_pluginConnector->initialize()) {
52 LogD("failed to initialize plugins");
60 ProviderCallbacks callbacks;
61 setProviderCallbacks(callbacks);
63 int ret = provider_init(ecore_x_display_get(),
68 LogD("failed to initialize provider");
75 bool BoxDaemonImpl::stop()
79 // deinitialize provider
82 // deinitialize existing plugins for web livebox
83 if (!m_pluginConnector->shutdown()) {
84 LogD("failed to shutdown plugins");
91 int BoxDaemonImpl::connectedCallback(ProviderEventArgPtr arg, void* data)
95 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
96 if (!provider_send_hello()) {
98 ecore_timer_add(MASTER_PROVIDER_PING_TIME, pingToMasterCallback, This);
104 int BoxDaemonImpl::disconnectedCallback(ProviderEventArgPtr arg, void* data)
108 aul_terminate_pid(getpid());
113 int BoxDaemonImpl::boxCreateCallback(
114 ProviderEventArgPtr arg,
115 int* width, int* height,
116 double* priority, void* data)
120 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
121 BoxInfoPtr info = This->initializeBoxInfo(arg);
126 if ((arg->info.lb_create.width == 0) || (arg->info.lb_create.height == 0)) {
127 livebox_service_get_size(LB_SIZE_TYPE_1x1, width, height);
129 *width = arg->info.lb_create.width;
130 *height = arg->info.lb_create.height;
133 info->boxWidth = *width;
134 info->boxHeight = *height;
135 info->priority = 1.0f;
136 info->period = arg->info.lb_create.period;
137 if (arg->info.lb_create.content) {
138 info->contentInfo = std::string(arg->info.lb_create.content);
142 LogD("--------------------------------------------");
143 LogD("boxId: %s", info->boxId.c_str());
144 LogD("InstanceId: %s", info->instanceId.c_str());
145 LogD("width: %d", info->boxWidth);
146 LogD("height: %d", info->boxHeight);
147 LogD("update period: %f", info->period);
148 LogD("--------------------------------------------");
150 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_ADD_BOX, info, This);
151 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
156 int BoxDaemonImpl::boxReCreateCallback(ProviderEventArgPtr arg, void* data)
160 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
161 BoxInfoPtr info = This->initializeBoxInfo(arg);
169 if ((arg->info.lb_recreate.width == 0) || (arg->info.lb_recreate.height == 0)) {
170 livebox_service_get_size(LB_SIZE_TYPE_1x1, width, height);
171 arg->info.lb_recreate.width = *width;
172 arg->info.lb_recreate.height = *height;
175 info->boxWidth = arg->info.lb_recreate.width;
176 info->boxHeight = arg->info.lb_recreate.height;
177 info->priority = 1.0f;
178 info->period = arg->info.lb_recreate.period;
179 if (arg->info.lb_recreate.content) {
180 info->contentInfo = std::string(arg->info.lb_recreate.content);
184 LogD("--------------------------------------------");
185 LogD("boxId: %s", info->boxId.c_str());
186 LogD("InstanceId: %s", info->instanceId.c_str());
187 LogD("width: %d", info->boxWidth);
188 LogD("height: %d", info->boxHeight);
189 LogD("update period: %f", info->period);
190 LogD("--------------------------------------------");
192 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_ADD_BOX, info, This);
193 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
198 int BoxDaemonImpl::boxDestroyCallback(ProviderEventArgPtr arg, void* data)
202 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
203 BoxInfoPtr info = This->initializeBoxInfo(arg);
208 LogD("--------------------------------------------");
209 LogD("boxId: %s", info->boxId.c_str());
210 LogD("InstanceId: %s", info->instanceId.c_str());
211 LogD("--------------------------------------------");
213 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_REMOVE_BOX, info, This);
214 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
219 int BoxDaemonImpl::pdCreateCallback(ProviderEventArgPtr arg, void* data)
223 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
224 BoxInfoPtr info = This->initializeBoxInfo(arg);
228 if (arg->info.pd_create.w == 0 || arg->info.pd_create.h == 0) {
232 info->pdWidth = arg->info.pd_create.w;
233 info->pdHeight = arg->info.pd_create.h;
234 info->pdX = arg->info.pd_create.x;
235 info->pdY = arg->info.pd_create.y;
237 LogD("--------------------------------------------");
238 LogD("boxId: %s", info->boxId.c_str());
239 LogD("InstanceId: %s", info->instanceId.c_str());
240 LogD("width: %d", info->pdWidth);
241 LogD("height: %d", info->pdHeight);
242 LogD("x: %f", info->pdX);
243 LogD("y: %f", info->pdY);
244 LogD("--------------------------------------------");
246 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_OPEN_PD, info, This);
247 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
252 int BoxDaemonImpl::pdDestroyCallback(ProviderEventArgPtr arg, void* data)
256 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
257 BoxInfoPtr info = This->initializeBoxInfo(arg);
262 LogD("--------------------------------------------");
263 LogD("boxId: %s", info->boxId.c_str());
264 LogD("InstanceId: %s", info->instanceId.c_str());
265 LogD("--------------------------------------------");
267 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_CLOSE_PD, info, This);
268 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
273 int BoxDaemonImpl::clickedCallback(ProviderEventArgPtr arg, void* data)
277 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
278 BoxInfoPtr info = This->initializeBoxInfo(arg);
283 int flag = web_provider_livebox_get_auto_launch(info->boxId.c_str());
288 BoxDaemonUtil::launchApplication(info->boxId, info->instanceId);
292 int BoxDaemonImpl::boxResizeCallback(ProviderEventArgPtr arg, void* data)
296 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
297 BoxInfoPtr info = This->initializeBoxInfo(arg);
301 if (arg->info.resize.w == 0 || arg->info.resize.h == 0) {
305 info->boxWidth = arg->info.resize.w;
306 info->boxHeight = arg->info.resize.h;
309 LogD("--------------------------------------------");
310 LogD("boxId: %s", info->boxId.c_str());
311 LogD("InstanceId: %s", info->instanceId.c_str());
312 LogD("width: %d", info->boxWidth);
313 LogD("height: %d", info->boxHeight);
314 LogD("--------------------------------------------");
316 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_RESIZE_BOX, info, This);
317 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
322 int BoxDaemonImpl::boxPauseCallback(ProviderEventArgPtr arg, void* data)
326 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
327 BoxInfoPtr info = This->initializeBoxInfo(arg);
333 LogD("--------------------------------------------");
334 LogD("boxId: %s", info->boxId.c_str());
335 LogD("InstanceId: %s", info->instanceId.c_str());
336 LogD("--------------------------------------------");
338 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_PAUSE_BOX, info, This);
339 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
344 int BoxDaemonImpl::boxResumeCallback(ProviderEventArgPtr arg, void* data)
348 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
349 BoxInfoPtr info = This->initializeBoxInfo(arg);
355 LogD("--------------------------------------------");
356 LogD("boxId: %s", info->boxId.c_str());
357 LogD("InstanceId: %s", info->instanceId.c_str());
358 LogD("--------------------------------------------");
360 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_RESUME_BOX, info, This);
361 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
366 int BoxDaemonImpl::pauseCallback(ProviderEventArgPtr arg, void* data)
370 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
372 LogD("--------------------------------------------");
373 LogD("web-provider is paused");
374 LogD("--------------------------------------------");
376 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_PAUSE_ALL, BoxInfoPtr(), This);
377 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
382 int BoxDaemonImpl::resumeCallback(ProviderEventArgPtr arg, void* data)
386 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
388 LogD("--------------------------------------------");
389 LogD("web-provider is resumed");
390 LogD("--------------------------------------------");
392 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_RESUME_ALL, BoxInfoPtr(), This);
393 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
398 int BoxDaemonImpl::boxPeriodChangeCallback(ProviderEventArgPtr arg, void* data)
401 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
402 BoxInfoPtr info = This->initializeBoxInfo(arg);
406 info->period = arg->info.set_period.period;
408 LogD("--------------------------------------------");
409 LogD("boxId: %s", info->boxId.c_str());
410 LogD("InstanceId: %s", info->instanceId.c_str());
411 LogD("period: %f", info->period);
412 LogD("--------------------------------------------");
414 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_CHANGE_PERIOD, info, This);
415 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
420 int BoxDaemonImpl::boxUpdateCallback(ProviderEventArgPtr arg, void* data)
424 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
425 BoxInfoPtr info = This->initializeBoxInfo(arg);
430 LogD("--------------------------------------------");
431 LogD("boxId: %s", info->boxId.c_str());
432 LogD("InstanceId: %s", info->instanceId.c_str());
433 LogD("--------------------------------------------");
435 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_UPDATE_BOX, info, This);
436 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
441 void BoxDaemonImpl::setProviderCallbacks(ProviderCallbacks& callbacks)
445 memset(&callbacks, 0, sizeof(callbacks));
446 callbacks.connected = BoxDaemonImpl::connectedCallback;
447 callbacks.disconnected = BoxDaemonImpl::disconnectedCallback;
448 callbacks.pause = BoxDaemonImpl::pauseCallback;
449 callbacks.resume = BoxDaemonImpl::resumeCallback;
450 callbacks.lb_create = BoxDaemonImpl::boxCreateCallback;
451 callbacks.lb_recreate = BoxDaemonImpl::boxReCreateCallback;
452 callbacks.lb_destroy = BoxDaemonImpl::boxDestroyCallback;
453 callbacks.lb_pause = BoxDaemonImpl::boxPauseCallback;
454 callbacks.lb_resume = BoxDaemonImpl::boxResumeCallback;
455 callbacks.pd_create = BoxDaemonImpl::pdCreateCallback;
456 callbacks.pd_destroy = BoxDaemonImpl::pdDestroyCallback;
457 callbacks.clicked = BoxDaemonImpl::clickedCallback;
458 callbacks.resize = BoxDaemonImpl::boxResizeCallback;
459 callbacks.update_content = BoxDaemonImpl::boxUpdateCallback;
460 callbacks.set_period = BoxDaemonImpl::boxPeriodChangeCallback;
463 const char* BoxDaemonImpl::getBoxType(const char* boxId)
471 const char* type = web_provider_livebox_get_box_type(boxId);
474 std::string serviceBoxId(boxId);
475 boxType = m_pluginConnector->getBoxType(serviceBoxId);
476 if (boxType.empty()) {
477 LogD("unrecognized box id");
480 type = strdup(boxType.c_str());
483 LogD("box id: %s, type: %s", boxId, type);
487 BoxInfoPtr BoxDaemonImpl::initializeBoxInfo(ProviderEventArgPtr arg)
495 if (!arg->pkgname || !arg->id) {
496 LogD("pkgname or id don't exist");
500 const char* type = getBoxType(arg->pkgname);
505 BoxInfoPtr infoPtr = BoxInfoPtr(new BoxInfo(type, arg->pkgname, arg->id));
511 Eina_Bool BoxDaemonImpl::pingToMasterCallback(void* data)
515 provider_send_ping();
517 return ECORE_CALLBACK_RENEW;
520 void BoxDaemonImpl::requestBoxJobCallback(void* data)
522 JobInfo* jobInfo = static_cast<JobInfo*>(data);
524 LogD("no information for job");
528 // just for debugging
529 //volatile int flag = 0;
530 //while(flag == 0) {;}
533 jobInfo->daemonImpl->m_pluginConnector->requestCommand(
534 jobInfo->cmdType, jobInfo->boxInfo);