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://www.tizenopensource.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);
128 arg->info.lb_create.width = *width;
129 arg->info.lb_create.height = *height;
132 info->boxWidth = arg->info.lb_create.width;
133 info->boxHeight = arg->info.lb_create.height;
134 info->priority = 1.0f;
135 info->period = arg->info.lb_create.period;
136 if (arg->info.lb_create.content) {
137 info->contentInfo = std::string(arg->info.lb_create.content);
141 LogD("--------------------------------------------");
142 LogD("boxId: %s", info->boxId.c_str());
143 LogD("InstanceId: %s", info->instanceId.c_str());
144 LogD("width: %d", info->boxWidth);
145 LogD("height: %d", info->boxHeight);
146 LogD("update period: %d", info->period);
147 LogD("--------------------------------------------");
149 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_ADD_BOX, info, This);
150 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
155 int BoxDaemonImpl::boxReCreateCallback(ProviderEventArgPtr arg, void* data)
159 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
160 BoxInfoPtr info = This->initializeBoxInfo(arg);
168 if ((arg->info.lb_recreate.width == 0) || (arg->info.lb_recreate.height == 0)) {
169 livebox_service_get_size(LB_SIZE_TYPE_1x1, width, height);
170 arg->info.lb_recreate.width = *width;
171 arg->info.lb_recreate.height = *height;
174 info->boxWidth = arg->info.lb_recreate.width;
175 info->boxHeight = arg->info.lb_recreate.height;
176 info->priority = 1.0f;
177 info->period = arg->info.lb_recreate.period;
178 if (arg->info.lb_recreate.content) {
179 info->contentInfo = std::string(arg->info.lb_recreate.content);
183 LogD("--------------------------------------------");
184 LogD("boxId: %s", info->boxId.c_str());
185 LogD("InstanceId: %s", info->instanceId.c_str());
186 LogD("width: %d", info->boxWidth);
187 LogD("height: %d", info->boxHeight);
188 LogD("update period: %f", info->period);
189 LogD("--------------------------------------------");
191 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_ADD_BOX, info, This);
192 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
197 int BoxDaemonImpl::boxDestroyCallback(ProviderEventArgPtr arg, void* data)
201 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
202 BoxInfoPtr info = This->initializeBoxInfo(arg);
207 LogD("--------------------------------------------");
208 LogD("boxId: %s", info->boxId.c_str());
209 LogD("InstanceId: %s", info->instanceId.c_str());
210 LogD("--------------------------------------------");
212 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_REMOVE_BOX, info, This);
213 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
218 int BoxDaemonImpl::pdCreateCallback(ProviderEventArgPtr arg, void* data)
222 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
223 BoxInfoPtr info = This->initializeBoxInfo(arg);
227 if (arg->info.pd_create.w == 0 || arg->info.pd_create.h == 0) {
231 info->pdWidth = arg->info.pd_create.w;
232 info->pdHeight = arg->info.pd_create.h;
234 LogD("--------------------------------------------");
235 LogD("boxId: %s", info->boxId.c_str());
236 LogD("InstanceId: %s", info->instanceId.c_str());
237 LogD("width: %d", info->pdWidth);
238 LogD("height: %d", info->pdHeight);
239 LogD("--------------------------------------------");
241 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_OPEN_PD, info, This);
242 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
247 int BoxDaemonImpl::pdDestroyCallback(ProviderEventArgPtr arg, void* data)
251 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
252 BoxInfoPtr info = This->initializeBoxInfo(arg);
257 LogD("--------------------------------------------");
258 LogD("boxId: %s", info->boxId.c_str());
259 LogD("InstanceId: %s", info->instanceId.c_str());
260 LogD("--------------------------------------------");
262 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_CLOSE_PD, info, This);
263 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
268 int BoxDaemonImpl::clickedCallback(ProviderEventArgPtr arg, void* data)
272 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
273 BoxInfoPtr info = This->initializeBoxInfo(arg);
278 int flag = web_provider_livebox_get_auto_launch(info->boxId.c_str());
283 BoxDaemonUtil::launchApplication(info->boxId, info->instanceId);
287 int BoxDaemonImpl::resizeCallback(ProviderEventArgPtr arg, void* data)
291 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
292 BoxInfoPtr info = This->initializeBoxInfo(arg);
296 if (arg->info.resize.w == 0 || arg->info.resize.h == 0) {
300 info->boxWidth = arg->info.resize.w;
301 info->boxHeight = arg->info.resize.h;
304 LogD("--------------------------------------------");
305 LogD("boxId: %s", info->boxId.c_str());
306 LogD("InstanceId: %s", info->instanceId.c_str());
307 LogD("width: %d", info->boxWidth);
308 LogD("height: %d", info->boxHeight);
309 LogD("--------------------------------------------");
311 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_RESIZE_BOX, info, This);
312 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
317 int BoxDaemonImpl::boxPauseCallback(ProviderEventArgPtr arg, void* data)
321 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
322 BoxInfoPtr info = This->initializeBoxInfo(arg);
328 LogD("--------------------------------------------");
329 LogD("boxId: %s", info->boxId.c_str());
330 LogD("InstanceId: %s", info->instanceId.c_str());
331 LogD("--------------------------------------------");
333 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_PAUSE_BOX, info, This);
334 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
339 int BoxDaemonImpl::boxResumeCallback(ProviderEventArgPtr arg, void* data)
343 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
344 BoxInfoPtr info = This->initializeBoxInfo(arg);
350 LogD("--------------------------------------------");
351 LogD("boxId: %s", info->boxId.c_str());
352 LogD("InstanceId: %s", info->instanceId.c_str());
353 LogD("--------------------------------------------");
355 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_RESUME_BOX, info, This);
356 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
361 int BoxDaemonImpl::pauseCallback(ProviderEventArgPtr arg, void* data)
365 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
367 LogD("--------------------------------------------");
368 LogD("web-provider is paused");
369 LogD("--------------------------------------------");
371 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_PAUSE_ALL, BoxInfoPtr(), This);
372 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
377 int BoxDaemonImpl::resumeCallback(ProviderEventArgPtr arg, void* data)
381 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
383 LogD("--------------------------------------------");
384 LogD("web-provider is resumed");
385 LogD("--------------------------------------------");
387 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_RESUME_ALL, BoxInfoPtr(), This);
388 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
393 int BoxDaemonImpl::updateContentCallback(ProviderEventArgPtr arg, void* data)
400 int BoxDaemonImpl::changePeriodCallback(ProviderEventArgPtr arg, void* data)
403 BoxDaemonImpl* This = static_cast<BoxDaemonImpl*>(data);
404 BoxInfoPtr info = This->initializeBoxInfo(arg);
408 info->period = arg->info.set_period.period;
410 LogD("--------------------------------------------");
411 LogD("boxId: %s", info->boxId.c_str());
412 LogD("InstanceId: %s", info->instanceId.c_str());
413 LogD("period: %f", info->period);
414 LogD("--------------------------------------------");
416 JobInfo* jobInfo = new JobInfo(REQUEST_CMD_CHANGE_PERIOD, info, This);
417 Ecore_Job* ret = ecore_job_add(requestBoxJobCallback, jobInfo);
422 void BoxDaemonImpl::setProviderCallbacks(ProviderCallbacks& callbacks)
426 memset(&callbacks, 0, sizeof(callbacks));
427 callbacks.connected = BoxDaemonImpl::connectedCallback;
428 callbacks.disconnected = BoxDaemonImpl::disconnectedCallback;
429 callbacks.pause = BoxDaemonImpl::pauseCallback;
430 callbacks.resume = BoxDaemonImpl::resumeCallback;
431 callbacks.lb_create = BoxDaemonImpl::boxCreateCallback;
432 callbacks.lb_recreate = BoxDaemonImpl::boxReCreateCallback;
433 callbacks.lb_destroy = BoxDaemonImpl::boxDestroyCallback;
434 callbacks.lb_pause = BoxDaemonImpl::boxPauseCallback;
435 callbacks.lb_resume = BoxDaemonImpl::boxResumeCallback;
436 callbacks.pd_create = BoxDaemonImpl::pdCreateCallback;
437 callbacks.pd_destroy = BoxDaemonImpl::pdDestroyCallback;
438 callbacks.clicked = BoxDaemonImpl::clickedCallback;
439 callbacks.resize = BoxDaemonImpl::resizeCallback;
440 callbacks.update_content = BoxDaemonImpl::updateContentCallback;
441 callbacks.set_period = BoxDaemonImpl::changePeriodCallback;
444 const char* BoxDaemonImpl::getBoxType(const char* boxId)
452 const char* type = web_provider_livebox_get_box_type(boxId);
454 std::string serviceBoxId(boxId);
455 std::string boxType = m_pluginConnector->getBoxType(serviceBoxId);
456 if (boxType.empty()) {
457 LogD("unrecognized box id");
460 type = boxType.c_str();
463 LogD("box id: %s, type: %s", boxId, type);
467 BoxInfoPtr BoxDaemonImpl::initializeBoxInfo(ProviderEventArgPtr arg)
475 if (!arg->pkgname || !arg->id) {
476 LogD("pkgname or id don't exist");
480 const char* type = getBoxType(arg->pkgname);
485 return BoxInfoPtr(new BoxInfo(type, arg->pkgname, arg->id));
488 Eina_Bool BoxDaemonImpl::pingToMasterCallback(void* data)
492 provider_send_ping();
494 return ECORE_CALLBACK_RENEW;
497 void BoxDaemonImpl::requestBoxJobCallback(void* data)
499 JobInfo* jobInfo = static_cast<JobInfo*>(data);
501 LogD("no information for job");
505 // just for debugging
506 //volatile int flag = 0;
507 //while(flag == 0) {;}
510 jobInfo->daemonImpl->m_pluginConnector->requestCommand(
511 jobInfo->cmdType, jobInfo->boxInfo);