2 * Copyright 2013 Samsung Electronics Co., Ltd
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
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.
23 #include <Elementary.h>
26 #include <Ecore_Evas.h>
33 #include <provider_buffer.h>
35 #include <mm_message.h>
36 #include <mm_player.h>
41 #include "CController.h"
44 CController *CController::m_pInstance = NULL;
45 Ecore_Timer *CController::m_pPing = NULL;
46 const double CController::m_nPingInterval = 120.0f;
53 int CController::s_CreateLB(struct event_arg *arg, int *width, int *height, double *priority, void *data)
59 arg->info.lb_create.out_content = NULL;
60 arg->info.lb_create.out_title = NULL;
62 DbgPrint("Content: %s\n", arg->info.lb_create.content);
64 video = CVideo::Create(TYPE_LB, arg->id, *width, *height);
71 int CController::s_RecreateLB(struct event_arg *arg, void *data)
75 DbgPrint("Content: %s\n", arg->info.lb_recreate.content);
77 video = CVideo::Create(TYPE_LB, arg->id, arg->info.lb_recreate.width, arg->info.lb_recreate.height);
84 int CController::s_DestroyLB(struct event_arg *arg, void *data)
89 video = CVideo::Find(TYPE_LB, arg->id);
93 win = CWindow::Find(TYPE_PD, arg->id);
100 int CController::s_ContentEvent(struct event_arg *arg, void *data)
104 video = CVideo::Find(TYPE_LB, arg->id);
111 int CController::s_Clicked(struct event_arg *arg, void *data)
115 video = CVideo::Find(TYPE_LB, arg->id);
117 ErrPrint("Instance is not found: %s\n", arg->id);
121 switch (video->State()) {
122 case CVideo::PLAYING:
125 case CVideo::STOPPED:
126 video->Play(CModel::GetInstance()->VideoFilename());
135 int CController::s_TextEvent(struct event_arg *arg, void *data)
139 video = CVideo::Find(TYPE_LB, arg->id);
146 int CController::s_Resize(struct event_arg *arg, void *data)
150 video = CVideo::Find(TYPE_LB, arg->id);
154 video->Resize(arg->info.resize.w, arg->info.resize.h);
158 int CController::s_SetPeriod(struct event_arg *arg, void *data)
162 video = CVideo::Find(TYPE_LB, arg->id);
169 int CController::s_ChangeGroup(struct event_arg *arg, void *data)
173 video = CVideo::Find(TYPE_LB, arg->id);
180 int CController::s_Pinup(struct event_arg *arg, void *data)
184 video = CVideo::Find(TYPE_LB, arg->id);
191 int CController::s_UpdateContent(struct event_arg *arg, void *data)
195 video = CVideo::Find(TYPE_LB, arg->id);
202 int CController::s_Pause(struct event_arg *arg, void *data)
205 ecore_timer_freeze(m_pPing);
210 int CController::s_Resume(struct event_arg *arg, void *data)
213 ecore_timer_thaw(m_pPing);
218 int CController::s_Disconnected(struct event_arg *arg, void *data)
221 ecore_timer_del(m_pPing);
225 aul_terminate_pid(getpid());
229 Eina_Bool CController::s_PingHandler(void *data)
231 provider_send_ping();
232 return ECORE_CALLBACK_RENEW;
235 int CController::s_Connected(struct event_arg *arg, void *data)
242 * Phase 2. Send "hello" signal to master
243 * Add "ping" timer (Master will wait 240 seconds)
245 if (provider_send_hello() < 0)
248 m_pPing = ecore_timer_add(m_nPingInterval, s_PingHandler, NULL);
250 ErrPrint("Failed to add a ping timer\n");
254 static void press_cb(void *data, Evas_Object *list, void *event_info)
257 Elm_Object_Item *item;
258 const char *filename;
261 TWindowData *win_data = (TWindowData *)data;
263 video = CVideo::Find(TYPE_LB, win_data->id);
265 ErrPrint("Video is not exists\n");
269 item = elm_list_selected_item_get(list);
271 ErrPrint("Item is not selected\n");
275 filename = elm_object_item_part_text_get(item, NULL);
277 ErrPrint("Selected item is not valid\n");
281 pathlen = strlen(filename) + strlen("/opt/usr/media/Videos/") + 1;
282 path = (char *)malloc(pathlen);
284 ErrPrint("Heap: %s\n", strerror(errno));
288 snprintf(path, pathlen, "/opt/usr/media/Videos/%s", filename);
289 CModel::GetInstance()->SetVideoFilename(path);
290 DbgPrint("Updated Video file: %s\n", path);
293 if (video->State() == CVideo::PLAYING)
296 video->Play(CModel::GetInstance()->VideoFilename());
299 int CController::s_CreatePD(struct event_arg *arg, void *data)
302 TWindowData *win_data;
310 win_data = (TWindowData *)malloc(sizeof(*win_data));
312 ErrPrint("Heap: %s\n", strerror(errno));
316 win = CWindow::Create(TYPE_PD, arg->id, arg->info.pd_create.w, arg->info.pd_create.h);
318 ErrPrint("Window for PID is not able to create\n");
323 parent = win->Object();
325 ErrPrint("Window is not valid\n");
330 list = elm_list_add(parent);
331 evas_object_geometry_get(parent, NULL, NULL, &w, &h);
332 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333 elm_list_multi_select_set(list, EINA_FALSE);
334 elm_list_mode_set(list, ELM_LIST_COMPRESS);
335 elm_scroller_bounce_set(list, EINA_TRUE, EINA_FALSE);
336 evas_object_resize(list, w, h);
337 evas_object_move(list, 0, 0);
338 evas_object_show(list);
340 handle = opendir("/opt/usr/media/Videos/");
344 while ((ent = readdir(handle)))
345 elm_list_item_append(list, ent->d_name, NULL, NULL /* end */, press_cb, win_data);
352 win_data->id = strdup(arg->id);
354 evas_object_del(list);
358 win_data->list = list;
360 evas_object_data_set(parent, "win_data", win_data);
364 int CController::s_DestroyPD(struct event_arg *arg, void *data)
367 TWindowData *win_data;
369 win = CWindow::Find(TYPE_PD, arg->id);
371 ErrPrint("PD Window for %s is not exists\n", arg->id);
375 win_data = (TWindowData *)evas_object_data_del(win->Object(), "win_data");
377 evas_object_del(win_data->list);
386 CController::CController(void)
391 CController::~CController(void)
399 ecore_timer_del(m_pPing);
404 int CController::Initialize(const char *name)
407 struct event_handler table;
409 if (CController::m_pInstance)
413 m_pInstance = new CController();
418 m_pInstance->m_sName = strdup(name);
419 if (!m_pInstance->m_sName) {
424 table.lb_create = CController::s_CreateLB;
425 table.lb_recreate = CController::s_RecreateLB;
426 table.lb_destroy = CController::s_DestroyLB;
427 table.content_event = CController::s_ContentEvent;
428 table.clicked = CController::s_Clicked;
429 table.text_signal = CController::s_TextEvent;
430 table.resize = CController::s_Resize;
431 table.set_period = CController::s_SetPeriod;
432 table.change_group = CController::s_ChangeGroup;
433 table.pinup = CController::s_Pinup;
434 table.update_content = CController::s_UpdateContent;
435 table.pause = CController::s_Pause;
436 table.resume = CController::s_Resume;
437 table.disconnected = CController::s_Disconnected;
438 table.connected = CController::s_Connected;
439 table.pd_create = CController::s_CreatePD;
440 table.pd_destroy = CController::s_DestroyPD;
442 ret = provider_init(ecore_x_display_get(), m_pInstance->m_sName, &table, NULL);
451 int CController::Finalize(void)