Changeset 847536504b95307eadfdb31d17902c85569e2e21

Show
Ignore:
Timestamp:
03/01/10 02:12:12 (5 months ago)
Author:
Nedko Arnaudov <nedko@…>
Children:
945b3aa6865654fd54707c298636a428c6510755
Parents:
e897f8a983f2f752ee61bfbfb296986b23726fb6
git-committer:
Nedko Arnaudov <nedko@arnaudov.name> / 2010-03-01T02:12:12Z+0200
Message:

Basic control of studio rooms

Files:
6 modified

Legend:

Unmodified
Added
Removed
  • daemon/control.c

    re897f8a r8475365  
    4949  ladish_room_handle room; 
    5050 
    51   if (!ladish_room_create(empty_room, "Empty", &room)) 
     51  if (!ladish_room_create(empty_room, "Empty", NULL, &room)) 
    5252  { 
    5353    log_error("ladish_room_create() failed."); 
     
    5757  list_add_tail(ladish_room_get_list_node(room), &g_rooms); 
    5858 
    59   if (!ladish_room_create(basic_room, "Basic", &room)) 
     59  if (!ladish_room_create(basic_room, "Basic", NULL, &room)) 
    6060  { 
    6161    log_error("ladish_room_create() failed."); 
     
    122122 
    123123  return true; 
     124} 
     125 
     126ladish_room_handle find_room_template_by_name(const char * name) 
     127{ 
     128  ladish_room_handle room; 
     129  struct list_head * node_ptr; 
     130 
     131  maybe_create_rooms(); 
     132 
     133  list_for_each(node_ptr, &g_rooms) 
     134  { 
     135    room = ladish_room_from_list_node(node_ptr); 
     136    if (strcmp(ladish_room_get_name(room), name) == 0) 
     137    { 
     138      return room; 
     139    } 
     140  } 
     141 
     142  return NULL; 
     143} 
     144 
     145ladish_room_handle find_room_template_by_uuid(const uuid_t uuid_ptr) 
     146{ 
     147  ladish_room_handle room; 
     148  struct list_head * node_ptr; 
     149  uuid_t uuid; 
     150 
     151  maybe_create_rooms(); 
     152 
     153  list_for_each(node_ptr, &g_rooms) 
     154  { 
     155    room = ladish_room_from_list_node(node_ptr); 
     156    ladish_room_get_uuid(room, uuid); 
     157    if (uuid_compare(uuid, uuid_ptr) == 0) 
     158    { 
     159      return room; 
     160    } 
     161  } 
     162 
     163  return NULL; 
    124164} 
    125165 
  • daemon/control.h

    rb6fe91e r8475365  
    2929#define __LASHD_DBUS_IFACE_CONTROL_H__ 
    3030 
     31#include "room.h" 
     32 
    3133extern const struct dbus_interface_descriptor g_lashd_interface_control; 
    3234 
     
    3739bool rooms_init(void); 
    3840void rooms_uninit(void); 
     41ladish_room_handle find_room_template_by_name(const char * name); 
     42ladish_room_handle find_room_template_by_uuid(const uuid_t uuid_ptr); 
    3943 
    4044#endif /* __LASHD_DBUS_IFACE_CONTROL_H__ */ 
  • daemon/room.c

    rb6fe91e r8475365  
    3232  uuid_t uuid; 
    3333  char * name; 
     34  uuid_t template_uuid; 
    3435}; 
    3536 
     
    3839  const uuid_t uuid_ptr, 
    3940  const char * name, 
     41  ladish_room_handle template, 
    4042  ladish_room_handle * room_handle_ptr) 
    4143{ 
     
    5153  if (uuid_ptr == NULL) 
    5254  { 
    53     uuid_generate(room_ptr->uuid); 
     55    if (template == NULL) 
     56    { 
     57      uuid_generate(room_ptr->uuid); 
     58    } 
     59    else 
     60    { 
     61      ladish_room_get_uuid(template, room_ptr->uuid); 
     62    } 
    5463  } 
    5564  else 
    5665  { 
    5766    uuid_copy(room_ptr->uuid, uuid_ptr); 
     67  } 
     68 
     69  if (template != NULL) 
     70  { 
     71    ladish_room_get_uuid(template, room_ptr->template_uuid); 
     72  } 
     73  else 
     74  { 
     75    uuid_clear(room_ptr->template_uuid); 
    5876  } 
    5977 
     
    90108} 
    91109 
     110bool ladish_room_get_template_uuid(ladish_room_handle room_handle, uuid_t uuid_ptr) 
     111{ 
     112  if (uuid_is_null(room_ptr->template_uuid)) 
     113  { 
     114    return false; 
     115  } 
     116 
     117  uuid_copy(uuid_ptr, room_ptr->template_uuid); 
     118  return true; 
     119} 
     120 
     121void ladish_room_get_uuid(ladish_room_handle room_handle, uuid_t uuid_ptr) 
     122{ 
     123  uuid_copy(uuid_ptr, room_ptr->uuid); 
     124} 
     125 
    92126#undef room_ptr 
    93127 
  • daemon/room.h

    rb6fe91e r8475365  
    3636  const uuid_t uuid_ptr, 
    3737  const char * name, 
     38  ladish_room_handle template, 
    3839  ladish_room_handle * room_handle_ptr); 
    3940 
     
    4647 
    4748const char * ladish_room_get_name(ladish_room_handle room_handle); 
     49bool ladish_room_get_template_uuid(ladish_room_handle room_handle, uuid_t uuid_ptr); 
     50void ladish_room_get_uuid(ladish_room_handle room_handle, uuid_t uuid_ptr); 
    4851 
    4952#endif /* #ifndef ROOM_H__9A1CF253_0A17_402A_BDF8_9BD72B467118__INCLUDED */ 
  • daemon/studio.c

    rdd24a9c r8475365  
    696696} 
    697697 
     698static void ladish_studio_new_room(struct dbus_method_call * call_ptr) 
     699{ 
     700  const char * room_name; 
     701  const char * template_name; 
     702  ladish_room_handle room; 
     703 
     704  dbus_error_init(&g_dbus_error); 
     705 
     706  if (!dbus_message_get_args(call_ptr->message, &g_dbus_error, DBUS_TYPE_STRING, &room_name, DBUS_TYPE_STRING, &template_name, DBUS_TYPE_INVALID)) 
     707  { 
     708    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s",  call_ptr->method_name, g_dbus_error.message); 
     709    dbus_error_free(&g_dbus_error); 
     710    return; 
     711  } 
     712 
     713  log_info("Request to create new studio room \"%s\" from template \"%s\".", room_name, template_name); 
     714 
     715  room = find_room_template_by_name(template_name); 
     716  if (room == NULL) 
     717  { 
     718    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Unknown room template \"%s\"",  template_name); 
     719    return; 
     720  } 
     721 
     722  if (!ladish_room_create(NULL, room_name, room, &room)) 
     723  { 
     724    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_room_create() failed."); 
     725    return; 
     726  } 
     727 
     728  list_add_tail(ladish_room_get_list_node(room), &g_studio.rooms); 
     729 
     730  //dbus_signal_emit(g_dbus_connection, STUDIO_OBJECT_PATH, IFACE_STUDIO, "RoomAppeared", ""); 
     731 
     732  method_return_new_void(call_ptr); 
     733} 
     734 
     735static void ladish_studio_get_room_list(struct dbus_method_call * call_ptr) 
     736{ 
     737  DBusMessageIter iter, array_iter; 
     738  DBusMessageIter struct_iter; 
     739  DBusMessageIter dict_iter; 
     740  struct list_head * node_ptr; 
     741  ladish_room_handle room; 
     742  const char * name; 
     743  uuid_t template_uuid; 
     744  ladish_room_handle template; 
     745  const char * template_name; 
     746 
     747  call_ptr->reply = dbus_message_new_method_return(call_ptr->message); 
     748  if (call_ptr->reply == NULL) 
     749  { 
     750    goto fail; 
     751  } 
     752 
     753  dbus_message_iter_init_append(call_ptr->reply, &iter); 
     754 
     755  if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sa{sv})", &array_iter)) 
     756  { 
     757    goto fail_unref; 
     758  } 
     759 
     760  list_for_each(node_ptr, &g_studio.rooms) 
     761  { 
     762    room = ladish_room_from_list_node(node_ptr); 
     763    name = ladish_room_get_name(room); 
     764 
     765    if (!ladish_room_get_template_uuid(room, template_uuid)) 
     766    { 
     767      template = NULL; 
     768      template_name = NULL; 
     769    } 
     770    else 
     771    { 
     772      template = find_room_template_by_uuid(template_uuid); 
     773      if (template != NULL) 
     774      { 
     775        template_name = ladish_room_get_name(template); 
     776      } 
     777      else 
     778      { 
     779        template_name = NULL; 
     780      } 
     781    } 
     782 
     783    if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter)) 
     784      goto fail_unref; 
     785 
     786    if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &name)) 
     787      goto fail_unref; 
     788 
     789    if (!dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter)) 
     790      goto fail_unref; 
     791 
     792    if (!dbus_maybe_add_dict_entry_string(&dict_iter, "template", template_name)) 
     793      goto fail_unref; 
     794 
     795    if (!dbus_message_iter_close_container(&struct_iter, &dict_iter)) 
     796      goto fail_unref; 
     797 
     798    if (!dbus_message_iter_close_container(&array_iter, &struct_iter)) 
     799      goto fail_unref; 
     800  } 
     801 
     802  if (!dbus_message_iter_close_container(&iter, &array_iter)) 
     803  { 
     804    goto fail_unref; 
     805  } 
     806 
     807  return; 
     808 
     809fail_unref: 
     810  dbus_message_unref(call_ptr->reply); 
     811  call_ptr->reply = NULL; 
     812 
     813fail: 
     814  log_error("Ran out of memory trying to construct method return"); 
     815} 
     816 
     817static void ladish_studio_delete_room(struct dbus_method_call * call_ptr) 
     818{ 
     819  const char * name; 
     820 
     821  dbus_error_init(&g_dbus_error); 
     822 
     823  if (!dbus_message_get_args(call_ptr->message, &g_dbus_error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) 
     824  { 
     825    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s",  call_ptr->method_name, g_dbus_error.message); 
     826    dbus_error_free(&g_dbus_error); 
     827    return; 
     828  } 
     829 
     830  log_info("Delete studio room request (%s)", name); 
     831 
     832  { 
     833    method_return_new_void(call_ptr); 
     834  } 
     835} 
     836 
    698837METHOD_ARGS_BEGIN(GetName, "Get studio name") 
    699838  METHOD_ARG_DESCRIBE_OUT("studio_name", "s", "Name of studio") 
     
    722861METHOD_ARGS_BEGIN(IsStarted, "Check whether studio is started") 
    723862  METHOD_ARG_DESCRIBE_OUT("started", "b", "Whether studio is started") 
     863METHOD_ARGS_END 
     864 
     865METHOD_ARGS_BEGIN(NewRoom, "New studio room") 
     866  METHOD_ARG_DESCRIBE_IN("room_name", "s", "Studio room name") 
     867  METHOD_ARG_DESCRIBE_IN("room_template_name", "s", "Room template name") 
     868METHOD_ARGS_END 
     869 
     870METHOD_ARGS_BEGIN(GetRoomList, "Get list of rooms in this studio") 
     871  METHOD_ARG_DESCRIBE_OUT("room_list", "a(sa{sv})", "List of studio rooms, name and properties") 
     872METHOD_ARGS_END 
     873 
     874METHOD_ARGS_BEGIN(DeleteRoom, "Delete studio room") 
     875  METHOD_ARG_DESCRIBE_IN("room_name", "s", "Name of studio room to delete") 
    724876METHOD_ARGS_END 
    725877 
     
    733885  METHOD_DESCRIBE(Stop, ladish_stop_studio) 
    734886  METHOD_DESCRIBE(IsStarted, ladish_studio_is_started) 
     887  METHOD_DESCRIBE(NewRoom, ladish_studio_new_room) 
     888  METHOD_DESCRIBE(GetRoomList, ladish_studio_get_room_list) 
     889  METHOD_DESCRIBE(DeleteRoom, ladish_studio_delete_room) 
    735890METHODS_END 
    736891 
  • ladish_control

    rb6fe91e r8475365  
    114114        print("    rdel <roomname>      - delete room") 
    115115        print("    rnew <roomname>      - new room") 
     116        print("    snewroom <name> <tname> - new studio room") 
     117        print("    srlist               - list studio rooms") 
     118        print("    sdelroom <name>      - delete studio room") 
    116119        sys.exit(0) 
    117120     
     
    203206                print("--- room delete") 
    204207                if index >= len(sys.argv): 
    205                     print("delete room command requires studio name argument") 
     208                    print("delete room command requires room name argument") 
    206209                    sys.exit() 
    207210 
     
    242245                    print("--- studio stop") 
    243246                    studio_iface.Stop() 
     247                elif arg == 'snewroom': 
     248                    print("--- new studio room") 
     249                    if index + 1 >= len(sys.argv): 
     250                        print("creation of studio room requires room name and room template name arguments") 
     251                        sys.exit() 
     252 
     253                    room_name = sys.argv[index] 
     254                    index += 1 
     255                    room_template_name = sys.argv[index] 
     256                    index += 1 
     257 
     258                    studio_iface.NewRoom(room_name, room_template_name) 
     259                elif arg == 'srlist': 
     260                    print("--- studio room list") 
     261                    for room in studio_iface.GetRoomList(): 
     262                        #print repr(room) 
     263                        name = room[0] 
     264                        if room[1].has_key("template"): 
     265                            template = str(room[1]["template"]) 
     266                        else: 
     267                            template = None 
     268 
     269                        if template: 
     270                            print('"%s" from template "%s"' % (name, template)) 
     271                        else: 
     272                            print('"%s"' % name) 
     273                elif arg == 'sdelroom': 
     274                    print("--- studio room delete") 
     275                    if index >= len(sys.argv): 
     276                        print("delete studio room command requires room name argument") 
     277                        sys.exit() 
     278 
     279                    arg = sys.argv[index] 
     280                    index += 1 
     281 
     282                    studio_iface.DeleteRoom(arg) 
    244283                else: 
    245284                    print("Unknown command '%s'" % arg)