2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.0 (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: %d", info->period);
148 LogD("--------------------------------------------");
150 return ecore_job_add(
151 requestBoxJobCallback,
152 new JobInfo(REQUEST_CMD_ADD_BOX, info, This))
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 return ecore_job_add(
193 requestBoxJobCallback,
194 new JobInfo(REQUEST_CMD_ADD_BOX, info, This))
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 return ecore_job_add(
214 requestBoxJobCallback,
215 new JobInfo(REQUEST_CMD_REMOVE_BOX, info, This))
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;
235 LogD("--------------------------------------------");
236 LogD("boxId: %s", info->boxId.c_str());
237 LogD("InstanceId: %s", info->instanceId.c_str());
238 LogD("width: %d", info->pdWidth);
239 LogD("height: %d", info->pdHeight);
240 LogD("--------------------------------------------");
242 return ecore_job_add(
243 requestBoxJobCallback,
244 new JobInfo(REQUEST_CMD_OPEN_PD, info, This))
248 int BoxDaemonImpl::pdDestroyCallback(ProviderEventArgPtr arg, void* data)
252 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
253 BoxInfoPtr info = This->initializeBoxInfo(arg);
258 LogD("--------------------------------------------");
259 LogD("boxId: %s", info->boxId.c_str());
260 LogD("InstanceId: %s", info->instanceId.c_str());
261 LogD("--------------------------------------------");
263 return ecore_job_add(
264 requestBoxJobCallback,
265 new JobInfo(REQUEST_CMD_CLOSE_PD, info, This))
269 int BoxDaemonImpl::clickedCallback(ProviderEventArgPtr arg, void* data)
273 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
274 BoxInfoPtr info = This->initializeBoxInfo(arg);
279 int flag = web_provider_livebox_get_auto_launch(info->boxId.c_str());
284 BoxDaemonUtil::launchApplication(info->boxId, info->instanceId);
288 int BoxDaemonImpl::resizeCallback(ProviderEventArgPtr arg, void* data)
292 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
293 BoxInfoPtr info = This->initializeBoxInfo(arg);
297 if (arg->info.resize.w == 0 || arg->info.resize.h == 0) {
301 info->boxWidth = arg->info.resize.w;
302 info->boxHeight = arg->info.resize.h;
305 LogD("--------------------------------------------");
306 LogD("boxId: %s", info->boxId.c_str());
307 LogD("InstanceId: %s", info->instanceId.c_str());
308 LogD("width: %d", info->boxWidth);
309 LogD("height: %d", info->boxHeight);
310 LogD("--------------------------------------------");
312 return ecore_job_add(
313 requestBoxJobCallback,
314 new JobInfo(REQUEST_CMD_RESIZE_BOX, info, This))
318 int BoxDaemonImpl::boxPauseCallback(ProviderEventArgPtr arg, void* data)
322 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
323 BoxInfoPtr info = This->initializeBoxInfo(arg);
329 LogD("--------------------------------------------");
330 LogD("boxId: %s", info->boxId.c_str());
331 LogD("InstanceId: %s", info->instanceId.c_str());
332 LogD("--------------------------------------------");
334 return ecore_job_add(
335 requestBoxJobCallback,
336 new JobInfo(REQUEST_CMD_PAUSE_BOX, info, This))
340 int BoxDaemonImpl::boxResumeCallback(ProviderEventArgPtr arg, void* data)
344 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
345 BoxInfoPtr info = This->initializeBoxInfo(arg);
351 LogD("--------------------------------------------");
352 LogD("boxId: %s", info->boxId.c_str());
353 LogD("InstanceId: %s", info->instanceId.c_str());
354 LogD("--------------------------------------------");
356 return ecore_job_add(
357 requestBoxJobCallback,
358 new JobInfo(REQUEST_CMD_RESUME_BOX, info, This))
362 int BoxDaemonImpl::pauseCallback(ProviderEventArgPtr arg, void* data)
366 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
368 LogD("--------------------------------------------");
369 LogD("web-provider is paused");
370 LogD("--------------------------------------------");
372 return ecore_job_add(
373 requestBoxJobCallback,
374 new JobInfo(REQUEST_CMD_PAUSE_ALL, BoxInfoPtr(), This))
378 int BoxDaemonImpl::resumeCallback(ProviderEventArgPtr arg, void* data)
382 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
384 LogD("--------------------------------------------");
385 LogD("web-provider is resumed");
386 LogD("--------------------------------------------");
388 return ecore_job_add(
389 requestBoxJobCallback,
390 new JobInfo(REQUEST_CMD_RESUME_ALL, BoxInfoPtr(), This))
394 int BoxDaemonImpl::updateContentCallback(ProviderEventArgPtr arg, void* data)
401 int BoxDaemonImpl::changePeriodCallback(ProviderEventArgPtr arg, void* data)
404 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
405 BoxInfoPtr info = This->initializeBoxInfo(arg);
409 info->period = arg->info.set_period.period;
411 LogD("--------------------------------------------");
412 LogD("boxId: %s", info->boxId.c_str());
413 LogD("InstanceId: %s", info->instanceId.c_str());
414 LogD("period: %f", info->period);
415 LogD("--------------------------------------------");
417 return ecore_job_add(
418 requestBoxJobCallback,
419 new JobInfo(REQUEST_CMD_CHANGE_PERIOD, info, This))
423 void BoxDaemonImpl::setProviderCallbacks(ProviderCallbacks& callbacks)
427 memset(&callbacks, 0, sizeof(callbacks));
428 callbacks.connected = BoxDaemonImpl::connectedCallback;
429 callbacks.disconnected = BoxDaemonImpl::disconnectedCallback;
430 callbacks.pause = BoxDaemonImpl::pauseCallback;
431 callbacks.resume = BoxDaemonImpl::resumeCallback;
432 callbacks.lb_create = BoxDaemonImpl::boxCreateCallback;
433 callbacks.lb_recreate = BoxDaemonImpl::boxReCreateCallback;
434 callbacks.lb_destroy = BoxDaemonImpl::boxDestroyCallback;
435 callbacks.lb_pause = BoxDaemonImpl::boxPauseCallback;
436 callbacks.lb_resume = BoxDaemonImpl::boxResumeCallback;
437 callbacks.pd_create = BoxDaemonImpl::pdCreateCallback;
438 callbacks.pd_destroy = BoxDaemonImpl::pdDestroyCallback;
439 callbacks.clicked = BoxDaemonImpl::clickedCallback;
440 callbacks.resize = BoxDaemonImpl::resizeCallback;
441 callbacks.update_content = BoxDaemonImpl::updateContentCallback;
442 callbacks.set_period = BoxDaemonImpl::changePeriodCallback;
445 const char* BoxDaemonImpl::getBoxType(const char* boxId)
453 const char* type = web_provider_livebox_get_box_type(boxId);
456 std::string serviceBoxId(boxId);
457 boxType = m_pluginConnector->getBoxType(serviceBoxId);
458 if (boxType.empty()) {
459 LogD("unrecognized box id");
462 type = strdup(boxType.c_str());
465 LogD("box id: %s, type: %s", boxId, type);
469 BoxInfoPtr BoxDaemonImpl::initializeBoxInfo(ProviderEventArgPtr arg)
477 if (!arg->pkgname || !arg->id) {
478 LogD("pkgname or id don't exist");
482 const char* type = getBoxType(arg->pkgname);
487 BoxInfoPtr infoPtr = BoxInfoPtr(new BoxInfo(type, arg->pkgname, arg->id));
493 Eina_Bool BoxDaemonImpl::pingToMasterCallback(void* data)
497 provider_send_ping();
499 return ECORE_CALLBACK_RENEW;
502 void BoxDaemonImpl::requestBoxJobCallback(void* data)
504 JobInfo* jobInfo = static_cast<JobInfo*>(data);
506 LogD("no information for job");
510 // just for debugging
511 //volatile int flag = 0;
512 //while(flag == 0) {;}
515 jobInfo->daemonImpl->m_pluginConnector->requestCommand(
516 jobInfo->cmdType, jobInfo->boxInfo);