Changeset 3abed82be77c9f7efdc2dc5a20ca1e2d5672e3ff

Show
Ignore:
Timestamp:
03/07/10 13:49:39 (5 months ago)
Author:
Nedko Arnaudov <nedko@…>
Children:
023639805f9421d73da40e60e167b318fdd75f59
Parents:
1f11f0968ec78d2ee1ae73c6604e2637725adf86
git-committer:
Nedko Arnaudov <nedko@arnaudov.name> / 2010-03-07T13:49:39Z+0200
Message:

Add callbacks for room studio signals to studio proxy

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • gui/main.c

    re6881d6 r3abed82  
    10541054} 
    10551055 
     1056static void room_appeared(const char * opath, const char * name, const char * template) 
     1057{ 
     1058  log_info("room \"%s\" appeared (%s). template is \"%s\"", name, opath, template); 
     1059} 
     1060 
     1061static void room_disappeared(const char * opath, const char * name, const char * template) 
     1062{ 
     1063  log_info("room \"%s\" disappeared (%s). template is \"%s\"", name, opath, template); 
     1064} 
     1065 
     1066static void room_changed(const char * opath, const char * name, const char * template) 
     1067{ 
     1068  log_info("%s changed. name is \"%s\". template is \"%s\"", opath, name, template); 
     1069} 
     1070 
    10561071void 
    10571072set_main_window_title( 
     
    13381353 
    13391354  studio_proxy_set_renamed_callback(on_studio_renamed); 
     1355  studio_proxy_set_room_callbacks(room_appeared, room_disappeared, room_changed); 
    13401356 
    13411357  g_signal_connect(G_OBJECT(g_main_win), "destroy", G_CALLBACK(gtk_main_quit), NULL); 
  • proxies/studio_proxy.c

    r15350de r3abed82  
    33 * LADI Session Handler (ladish) 
    44 * 
    5  * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name> 
     5 * Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name> 
    66 * 
    77 ************************************************************************** 
     
    3333static void (* g_crashed_callback)(void) = NULL; 
    3434 
     35static void (* g_room_appeared_calback)(const char * opath, const char * name, const char * template) = NULL; 
     36static void (* g_room_disappeared_calback)(const char * opath, const char * name, const char * template) = NULL; 
     37static void (* g_room_changed_calback)(const char * opath, const char * name, const char * template) = NULL; 
     38 
    3539static void on_studio_renamed(void * context, DBusMessage * message_ptr) 
    3640{ 
     
    5357} 
    5458 
     59static bool extract_room_info(DBusMessageIter * iter_ptr, const char ** opath, const char ** name, const char ** template) 
     60{ 
     61  dbus_message_iter_get_basic(iter_ptr, opath); 
     62  //log_info("opath is \"%s\"", *opath); 
     63  dbus_message_iter_next(iter_ptr); 
     64 
     65  if (!dbus_iter_get_dict_entry_string(iter_ptr, "name", name)) 
     66  { 
     67    log_error("dbus_iter_get_dict_entry() failed"); 
     68    return false; 
     69  } 
     70  //log_info("name is \"%s\"", *name); 
     71 
     72  if (!dbus_iter_get_dict_entry_string(iter_ptr, "template", template)) 
     73  { 
     74    *template = NULL; 
     75  } 
     76  //log_info("template is \"%s\"", *template); 
     77 
     78  return true; 
     79} 
     80 
     81static bool extract_room_info_from_signal(DBusMessage * message_ptr, const char ** opath, const char ** name, const char ** template) 
     82{ 
     83  const char * signature; 
     84  DBusMessageIter iter; 
     85 
     86  signature = dbus_message_get_signature(message_ptr); 
     87  if (strcmp(signature, "sa{sv}") != 0) 
     88  { 
     89    log_error("Invalid signature of room signal"); 
     90    return false; 
     91  } 
     92 
     93  dbus_message_iter_init(message_ptr, &iter); 
     94 
     95  return extract_room_info(&iter, opath, name, template); 
     96} 
     97 
    5598static void on_studio_started(void * context, DBusMessage * message_ptr) 
    5699{ 
     
    85128static void on_room_appeared(void * context, DBusMessage * message_ptr) 
    86129{ 
     130  const char * opath; 
     131  const char * name; 
     132  const char * template; 
     133 
    87134  log_info("RoomAppeared"); 
     135 
     136  if (g_room_appeared_calback != NULL && extract_room_info_from_signal(message_ptr, &opath, &name, &template)) 
     137  { 
     138    g_room_appeared_calback(opath, name, template); 
     139  } 
    88140} 
    89141 
    90142static void on_room_disappeared(void * context, DBusMessage * message_ptr) 
    91143{ 
     144  const char * opath; 
     145  const char * name; 
     146  const char * template; 
     147 
    92148  log_info("RoomDisappeared"); 
     149 
     150  if (g_room_disappeared_calback != NULL && extract_room_info_from_signal(message_ptr, &opath, &name, &template)) 
     151  { 
     152    g_room_disappeared_calback(opath, name, template); 
     153  } 
     154} 
     155 
     156static void on_room_changed(void * context, DBusMessage * message_ptr) 
     157{ 
     158  const char * opath; 
     159  const char * name; 
     160  const char * template; 
     161 
     162  log_info("RoomChanged"); 
     163 
     164  if (g_room_changed_calback != NULL && extract_room_info_from_signal(message_ptr, &opath, &name, &template)) 
     165  { 
     166    g_room_changed_calback(opath, name, template); 
     167  } 
    93168} 
    94169 
     
    103178  {"RoomAppeared", on_room_appeared}, 
    104179  {"RoomDisappeared", on_room_disappeared}, 
     180  {"RoomChanged", on_room_changed}, 
    105181  {NULL, NULL} 
    106182}; 
     
    201277  return true; 
    202278} 
     279 
     280void 
     281studio_proxy_set_room_callbacks( 
     282  void (* appeared)(const char * opath, const char * name, const char * template), 
     283  void (* disappeared)(const char * opath, const char * name, const char * template), 
     284  void (* changed)(const char * opath, const char * name, const char * template)) 
     285{ 
     286  DBusMessage * reply_ptr; 
     287  const char * signature; 
     288  DBusMessageIter top_iter; 
     289  DBusMessageIter array_iter; 
     290  DBusMessageIter struct_iter; 
     291  const char * opath; 
     292  const char * name; 
     293  const char * template; 
     294 
     295  g_room_appeared_calback = appeared; 
     296  g_room_disappeared_calback = disappeared; 
     297  g_room_changed_calback = changed; 
     298 
     299  if (!dbus_call(SERVICE_NAME, STUDIO_OBJECT_PATH, IFACE_STUDIO, "GetRoomList", "", NULL, &reply_ptr)) 
     300  { 
     301    log_error("Cannot fetch studio room list"); 
     302    return; 
     303  } 
     304 
     305  signature = dbus_message_get_signature(reply_ptr); 
     306  if (strcmp(signature, "a(sa{sv})") != 0) 
     307  { 
     308    log_error("Invalid signature of GetRoomList reply"); 
     309    goto unref; 
     310  } 
     311 
     312  dbus_message_iter_init(reply_ptr, &top_iter); 
     313 
     314  for (dbus_message_iter_recurse(&top_iter, &array_iter); 
     315       dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID; 
     316       dbus_message_iter_next(&array_iter)) 
     317  { 
     318    dbus_message_iter_recurse(&array_iter, &struct_iter); 
     319 
     320    if (!extract_room_info(&struct_iter, &opath, &name, &template)) 
     321    { 
     322      log_error("extract_room_info() failed."); 
     323      goto unref; 
     324    } 
     325 
     326    g_room_appeared_calback(opath, name, template); 
     327  } 
     328 
     329unref: 
     330  dbus_message_unref(reply_ptr); 
     331} 
  • proxies/studio_proxy.h

    r15350de r3abed82  
    33 * LADI Session Handler (ladish) 
    44 * 
    5  * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name> 
     5 * Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name> 
    66 * 
    77 ************************************************************************** 
     
    4545bool studio_proxy_is_started(bool * is_started_ptr); 
    4646 
     47void 
     48studio_proxy_set_room_callbacks( 
     49  void (* appeared)(const char * opath, const char * name, const char * template), 
     50  void (* disappeared)(const char * opath, const char * name, const char * template), 
     51  void (* changed)(const char * opath, const char * name, const char * template)); 
     52 
    4753#endif /* #ifndef STUDIO_PROXY_H__2CEC623F_C998_4618_A947_D1A0016DF978__INCLUDED */