Exemplo n.º 1
0
Arquivo: gslist.c Projeto: gtco/cxo
GSList*
g_slist_insert_sorted (GSList       *list,
                       gpointer      data,
                       GCompareFunc  func)
{
  GSList *tmp_list = list;
  GSList *prev_list = NULL;
  GSList *new_list;
  gint cmp;
 
  g_return_val_if_fail (func != NULL, list);

  if (!list)
    {
      new_list = g_slist_alloc();
      new_list->data = data;
      return new_list;
    }
 
  cmp = (*func) (data, tmp_list->data);
 
  while ((tmp_list->next) && (cmp > 0))
    {
      prev_list = tmp_list;
      tmp_list = tmp_list->next;
      cmp = (*func) (data, tmp_list->data);
    }

  new_list = g_slist_alloc();
  new_list->data = data;

  if ((!tmp_list->next) && (cmp > 0))
    {
      tmp_list->next = new_list;
      return list;
    }
  
  if (prev_list)
    {
      prev_list->next = new_list;
      new_list->next = tmp_list;
      return list;
    }
  else
    {
      new_list->next = list;
      return new_list;
    }
}
Evas_Object* viewer_list_create(Evas_Object *win)
{
	__COMMON_FUNC_ENTER__;

	assertm_if(NULL == win, "NULL!!");

	assertm_if(NULL != viewer_list, "Err!!");
	viewer_list = elm_genlist_add(win);
	elm_object_style_set(viewer_list, "dialogue");
	assertm_if(NULL == viewer_list, "NULL!!");

	elm_genlist_mode_set(viewer_list, ELM_LIST_LIMIT);

	evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);

	container = NULL;
	container = g_slist_alloc();
	assertm_if(NULL == container, "NULL!!");

	itc.item_style = "dialogue/2text.2icon.3.tb";
	itc.func.text_get = _gl_listview_text_get;
	itc.func.content_get = _gl_listview_content_get;
	itc.func.state_get = NULL;
	itc.func.del = _gl_listview_del;

	__COMMON_FUNC_EXIT__;
	return viewer_list;
}
Exemplo n.º 3
0
void read_by_uuid_cb(guint8 status, const guint8 *pdu, guint16 plen,
                     gpointer user_data)
{
    struct att_data_list *list;
    GSList               *bl_value_list = NULL;
    cb_ctx_t             *cb_ctx = user_data;

    printf_dbg("[CB] IN read_by_uuid_cb\n");
    if (status) {
        cb_ctx->cb_ret_val = BL_REQUEST_FAIL_ERROR;
        sprintf(cb_ctx->cb_ret_msg, "Read by uuid callback: Failure: %s\n",
                att_ecode2str(status));
        goto error;
    }

    list = dec_read_by_type_resp(pdu, plen);
    if (list == NULL) {
        strcpy(cb_ctx->cb_ret_msg, "Read by uuid callback: Nothing found\n");
        cb_ctx->cb_ret_val = BL_NO_ERROR;
        goto error;
    }

    for (int i = 0; i < list->num; i++) {
        bl_value_t *bl_value = bl_value_new(NULL, att_get_u16(list->data[i]),
                                            list->len - 2, list->data[i] + 2);
        if (bl_value == NULL) {
            cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
            strcpy(cb_ctx->cb_ret_msg,
                   "Read by uuid callback: Malloc error\n");
            goto error;
        }

        // Add it to the value list
        if (bl_value_list == NULL) {
            bl_value_list = g_slist_alloc();
            if (bl_value_list == NULL) {
                cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
                strcpy(cb_ctx->cb_ret_msg,
                       "Read by uuid callback: Malloc error\n");
                goto error;
            }
            bl_value_list->data = bl_value;
        } else {
            bl_value_list = g_slist_append(bl_value_list, bl_value);
        }
    }

    att_data_list_free(list);

    cb_ctx->cb_ret_pointer = bl_value_list;
    cb_ctx->cb_ret_val     = BL_NO_ERROR;
    goto exit;

error:
    if (bl_value_list)
        bl_value_list_free(bl_value_list);
exit:
    g_mutex_unlock(&cb_ctx->pending_cb_mtx);
    printf_dbg("[CB] OUT read_by_uuid_cb\n");
}
Exemplo n.º 4
0
void
gdm_error_trap_push (void)
{
        GSList *node;
        GdmErrorTrap *trap;

        if (gdm_error_trap_free_list) {
                node = gdm_error_trap_free_list;
                gdm_error_trap_free_list = gdm_error_trap_free_list->next;
        } else {
                node = g_slist_alloc ();
                node->data = g_new (GdmErrorTrap, 1);
        }

        node->next = gdm_error_traps;
        gdm_error_traps = node;

        trap = node->data;
        trap->old_handler = XSetErrorHandler (gdm_x_error);
        trap->error_code = _gdm_error_code;
        trap->error_warnings = _gdm_error_warnings;

        _gdm_error_code = 0;
        _gdm_error_warnings = 0;
}
Exemplo n.º 5
0
void char_by_uuid_cb(GSList *characteristics, guint8 status,
                     gpointer user_data)
{
    GSList   *l            = NULL;
    GSList   *bl_char_list = NULL;
    cb_ctx_t *cb_ctx       = user_data;

    printf_dbg(" IN char_by_uuid\n");
    if (status) {
        cb_ctx->cb_ret_val = BL_REQUEST_FAIL_ERROR;
        sprintf(cb_ctx->cb_ret_msg,
                "Characteristic by UUID callback: Failure: %s\n",
                att_ecode2str(status));
        goto error;
    }

    for (l = characteristics; l; l = l->next) {
        // Extract data
        struct gatt_char *chars = l->data;
        bl_char_t *bl_char = bl_char_new(chars->uuid, chars->handle,
                                         chars->properties,
                                         chars->value_handle);

        // Add it to the characteristic
        if (bl_char == NULL) {
            cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
            strcpy(cb_ctx->cb_ret_msg,
                   "Characteristic by UUID callback: Malloc error\n");
            goto error;
        }

        // Append it to the list
        if (bl_char_list == NULL) {
            bl_char_list = g_slist_alloc();
            if (bl_char_list == NULL) {
                cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
                strcpy(cb_ctx->cb_ret_msg,
                       "Characteristic by UUID callback: Malloc error\n");
                goto error;
            }
            bl_char_list->data = bl_char;
        } else {
            bl_char_list = g_slist_append(bl_char_list, bl_char);
        }
    }

    cb_ctx->cb_ret_val     = BL_NO_ERROR;
    cb_ctx->cb_ret_pointer = bl_char_list;
    goto exit;

error:
    if (bl_char_list)
        bl_char_list_free(bl_char_list);
exit:
    if (l)
        g_slist_free(l);
    g_mutex_unlock(&cb_ctx->pending_cb_mtx);
    printf_dbg("OUT char_by_uuid\n");
}
Exemplo n.º 6
0
static void
add_new_waiting_for (SymbolDBViewLocals *dbvl, gint parent_symbol_id, 
					 const gchar* symbol_name, 
					 gint symbol_id, const GdkPixbuf *pixbuf)
{
	SymbolDBViewLocalsPriv *priv;
	gpointer node;
	
	g_return_if_fail (dbvl != NULL);	
	priv = dbvl->priv;

	/* we don't want a negative parent_symbol_id */
	if (parent_symbol_id < 0)
		return;	
	
	/* check if we already have some children waiting for a 
	 * specific father to be inserted, then add this symbol_id to the list 
	 * (or create a new one)
	 */
	WaitingForSymbol *wfs;
			
	wfs = g_new0 (WaitingForSymbol, 1);
	wfs->child_symbol_id = symbol_id;
	wfs->child_symbol_name = g_strdup (symbol_name);
	wfs->pixbuf = pixbuf;
				
/*	DEBUG_PRINT ("add_new_waiting_for (): looking up waiting_for %d", 
				 parent_symbol_id);*/
	node = g_tree_lookup (priv->waiting_for, GINT_TO_POINTER (parent_symbol_id));
	if (node == NULL) 
	{
		/* no lists already set. Create one. */
		GSList *slist;					
		slist = g_slist_alloc ();			
				
		slist = g_slist_prepend (slist, wfs);
					
		/*DEBUG_PRINT ("add_new_waiting_for (): NEW adding to "
					 "waiting_for [%d]", parent_symbol_id);*/
				
		/* add it to the binary tree. */
		g_tree_insert (priv->waiting_for, GINT_TO_POINTER (parent_symbol_id), 
							   slist);
	}
	else 
	{
		/* found a list */
		GSList *slist;
		slist = (GSList*)node;
		
		/*DEBUG_PRINT ("prepare_for_adding (): NEW adding to "
					 "parent_waiting_for_list [%d] %s",
				 	parent_symbol_id, symbol_name);*/
		slist = g_slist_prepend (slist, wfs);
				
		g_tree_replace (priv->waiting_for, GINT_TO_POINTER (parent_symbol_id), 
						slist);
	}	
}
Exemplo n.º 7
0
void primary_all_cb(GSList *services, guint8 status,
                    gpointer user_data)
{
  GSList *l = NULL;
  GSList *bl_primary_list = NULL;

  printf_dbg("[CB] IN Primary_all_cb\n");
  if (status) {
    cb_ret_val = BL_REQUEST_FAIL_ERROR;
    sprintf(cb_ret_msg, "Primary callback: Failure: %s\n",
            att_ecode2str(status));
    goto error;
  }

  if (services == NULL) {
    cb_ret_val = BL_NO_ERROR;
    strcpy(cb_ret_msg, "Primary callback: Nothing found\n");
    goto exit;
  }

  for (l = services; l; l = l->next) {
    struct gatt_primary *prim = l->data;
    bl_primary_t *bl_primary = bl_primary_new(prim->uuid, prim->changed,
        prim->range.start, prim->range.end);

    g_free(prim);

    if (bl_primary == NULL) {
      cb_ret_val = BL_MALLOC_ERROR;
      strcpy(cb_ret_msg, "Primary callback: Malloc error\n");
      goto error;
    }
    if (bl_primary_list == NULL) {
      bl_primary_list = g_slist_alloc();
      if (bl_primary_list == NULL) {
        cb_ret_val = BL_MALLOC_ERROR;
        strcpy(cb_ret_msg, "Primary callback: Malloc error\n");
        goto error;
      }
      bl_primary_list->data = bl_primary;
    } else {
      bl_primary_list = g_slist_append(bl_primary_list, bl_primary);
    }
  }

  cb_ret_val = BL_NO_ERROR;
  cb_ret_pointer = bl_primary_list;
  strcpy(cb_ret_msg, "Primary callback: Sucess\n");
  goto exit;

 error:
  if (bl_primary_list)
    bl_primary_list_free(bl_primary_list);
 exit:
  if (l)
    g_slist_free(l);
  g_mutex_unlock(pending_callback);
  printf_dbg("[CB] OUT primary_all_cb\n");
}
Exemplo n.º 8
0
void primary_by_uuid_cb(GSList *ranges, guint8 status,
                        gpointer user_data)
{
    GSList   *l;
    GSList   *bl_primary_list = NULL;
    cb_ctx_t *cb_ctx = user_data;

    printf_dbg("IN primary_by_uuid_cb\n");
    if (status) {
        cb_ctx->cb_ret_val = BL_REQUEST_FAIL_ERROR;
        sprintf(cb_ctx->cb_ret_msg, "Primary by UUID callback: Failure: %s\n",
                att_ecode2str(status));
        goto error;
    }
    if (ranges == NULL) {
        cb_ctx->cb_ret_val = BL_NO_ERROR;
        strcpy(cb_ctx->cb_ret_msg,
               "Primary by UUID callback: Nothing found\n");
        goto exit;
    }

    for (l = ranges; l; l = l->next) {
        struct att_range *range = l->data;
        bl_primary_t *bl_primary = bl_primary_new(NULL, 0, range->start,
                                                  range->end);
        free(range);

        if (bl_primary == NULL) {
            cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
            strcpy(cb_ctx->cb_ret_msg,
                   "Primary by UUID callback: Malloc error\n");
            goto error;
        }
        if (bl_primary_list == NULL) {
            bl_primary_list = g_slist_alloc();

            if (bl_primary_list == NULL) {
                cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
                strcpy(cb_ctx->cb_ret_msg,
                       "Primary by UUID callback: Malloc error\n");
                goto error;
            }
            bl_primary_list->data = bl_primary;
        } else {
            bl_primary_list = g_slist_append(bl_primary_list, bl_primary);
        }
    }
    cb_ctx->cb_ret_val = BL_NO_ERROR;
    cb_ctx->cb_ret_pointer = bl_primary_list;
    goto exit;

error:
    if (bl_primary_list)
        bl_primary_list_free(bl_primary_list);
exit:
    g_mutex_unlock(&cb_ctx->pending_cb_mtx);
    printf_dbg("OUT primary_by_uuid_cb\n");
}
Exemplo n.º 9
0
/* This is also a list node constructor. */
GSList*
g_slist_prepend (GSList *list, gpointer data)
{
	GSList *head = g_slist_alloc ();
	head->data = data;
	head->next = list;

	return head;
}
Exemplo n.º 10
0
void included_cb(GSList *includes, guint8 status, gpointer user_data)
{
    GSList   *l                = NULL;
    GSList   *bl_included_list = NULL;
    cb_ctx_t *cb_ctx           = user_data;

    printf_dbg("IN included_cb\n");
    if (status) {
        cb_ctx->cb_ret_val = BL_REQUEST_FAIL_ERROR;
        sprintf(cb_ctx->cb_ret_msg, "Included callback: Failure: %s\n",
                att_ecode2str(status));
        goto error;
    }

    if (includes == NULL) {
        cb_ctx->cb_ret_val = BL_NO_ERROR;
        strcpy(cb_ctx->cb_ret_msg, "Included callback: Nothing found\n");
        goto exit;
    }

    for (l = includes; l; l = l->next) {
        struct gatt_included *incl = l->data;
        bl_included_t *bl_included = bl_included_new(incl->uuid, incl->handle,
                                                     incl->range.start,
                                                     incl->range.end);
        if (bl_included == NULL) {
            cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
            strcpy(cb_ctx->cb_ret_msg, "Included callback: Malloc error\n");
            goto error;
        }
        if (bl_included_list == NULL) {
            bl_included_list = g_slist_alloc();
            if (bl_included_list == NULL) {
                cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
                strcpy(cb_ctx->cb_ret_msg,
                       "Included callback: Malloc error\n");
                goto error;
            }
            bl_included_list->data = bl_included;
        } else {
            bl_included_list = g_slist_append(bl_included_list, bl_included);
        }
    }

    cb_ctx->cb_ret_val     = BL_NO_ERROR;
    cb_ctx->cb_ret_pointer = bl_included_list;
    goto exit;

error:
    if (bl_included_list)
        bl_included_list_free(bl_included_list);
exit:
    if (l)
        g_slist_free(l);
    g_mutex_unlock(&cb_ctx->pending_cb_mtx);
    printf_dbg("OUT included_cb\n");
}
Exemplo n.º 11
0
GSList *local_interfaces_to_list(void)
{
    GSList *interfaces = NULL;
#ifdef HAVE_GETIFADDRS
    struct ifaddrs *ifap;
    struct ifaddrs *ifa;
    int family;
    char ip[INET6_ADDRSTRLEN];

    if (getifaddrs(&ifap)) {
	goto end;
    }

    interfaces = g_slist_alloc();

    for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
	if (ifa->ifa_addr == NULL)
	    continue;

	family = ifa->ifa_addr->sa_family;

	memset(ip, 0x0, INET6_ADDRSTRLEN);

	switch (family) {
	    case AF_INET:
		{
		    struct sockaddr_in *addr4 = (struct sockaddr_in *)ifa->ifa_addr;
		    ws_inet_ntop4(&addr4->sin_addr, ip, sizeof(ip));
		    break;
		}

	    case AF_INET6:
		{
		    struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)ifa->ifa_addr;
		    ws_inet_ntop6(&addr6->sin6_addr, ip, sizeof(ip));
		    break;
		}

	    default:
		break;
	}

	/* skip loopback addresses */
	if (!g_strcmp0(ip, "127.0.0.1") || !g_strcmp0(ip, "::1"))
	    continue;

	if (*ip) {
	    interfaces = g_slist_prepend(interfaces, g_strdup(ip));
	}
    }
    freeifaddrs(ifap);
end:
#endif /* HAVE_GETIFADDRS */
    return interfaces;
}
Exemplo n.º 12
0
GSList *
g_slist_prepend (GSList * list, gpointer data)
{
	GSList *new_list;

	new_list = g_slist_alloc ();
	new_list->data = data;
	new_list->next = list;

	return new_list;
}
Exemplo n.º 13
0
void init_cmd_system()
{
  if( cmd_system_is_init() ) return;
  
  _cmd_list = g_slist_alloc();
 if( !_cmd_list )
 {
   Log( FATAL, "Command System Could not be Initialized" );
   exit( -1 );
 }
 _cmd_list->data = NULL;
}
Exemplo n.º 14
0
GSList*
g_slist_insert_before (GSList  *slist,
		       GSList  *sibling,
		       gpointer data)
{
  if (!slist)
    {
      slist = g_slist_alloc ();
      slist->data = data;
      g_return_val_if_fail (sibling == NULL, slist);
      return slist;
    }
  else
    {
      GSList *node, *last = NULL;

      for (node = slist; node; last = node, node = last->next)
	if (node == sibling)
	  break;
      if (!last)
	{
	  node = g_slist_alloc ();
	  node->data = data;
	  node->next = slist;

	  return node;
	}
      else
	{
	  node = g_slist_alloc ();
	  node->data = data;
	  node->next = last->next;
	  last->next = node;

	  return slist;
	}
    }
}
Exemplo n.º 15
0
GSList*
g_slist_copy (GSList *list)
{
  GSList *new_list = NULL;

  if (list)
    {
      GSList *last;

      new_list = g_slist_alloc ();
      new_list->data = list->data;
      last = new_list;
      list = list->next;
      while (list)
	{
	  last->next = g_slist_alloc ();
	  last = last->next;
	  last->data = list->data;
	  list = list->next;
	}
    }

  return new_list;
}
Exemplo n.º 16
0
GSList *
g_slist_append (GSList * list, gpointer data)
{
	GSList *new_list;
	GSList *last;

	new_list = g_slist_alloc ();
	new_list->data = data;

	if (list)
	{
		last = g_slist_last (list);
		last->next = new_list;

		return list;
	} else
		return new_list;
}
Exemplo n.º 17
0
Arquivo: gslist.c Projeto: gtco/cxo
GSList*
g_slist_insert (GSList   *list,
		gpointer  data,
		gint      position)
{
  GSList *prev_list;
  GSList *tmp_list;
  GSList *new_list;

  if (position < 0)
    return g_slist_append (list, data);
  else if (position == 0)
    return g_slist_prepend (list, data);

  new_list = g_slist_alloc ();
  new_list->data = data;

  if (!list)
    return new_list;

  prev_list = NULL;
  tmp_list = list;

  while ((position-- > 0) && tmp_list)
    {
      prev_list = tmp_list;
      tmp_list = tmp_list->next;
    }

  if (prev_list)
    {
      new_list->next = prev_list->next;
      prev_list->next = new_list;
    }
  else
    {
      new_list->next = list;
      list = new_list;
    }

  return list;
}
bool service_list_upgradable_packages_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	struct package_list_info plistinfo;
	GSList *iter;
	jvalue_ref reply_obj = NULL;
	jvalue_ref pkglist_obj = NULL;
	jvalue_ref pkgname_obj = NULL;

	if (opkg_new()) {
		luna_service_message_reply_error_internal(handle, message);
		return true;
	}

	plistinfo.pkgs = g_slist_alloc();
	opkg_list_upgradable_packages(upgradable_package_list_cb, &plistinfo);

	reply_obj = jobject_create();
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	pkglist_obj = jarray_create(NULL);

	for (iter = plistinfo.pkgs; iter != NULL; iter = g_slist_next(iter)) {
		if (iter->data != NULL) {
			gchar *pkgname = iter->data;
			pkgname_obj = jstring_create(pkgname);
			jarray_append(pkglist_obj, pkgname_obj);
		}
	}

	jobject_put(reply_obj, J_CSTR_TO_JVAL("upgradablePackages"), pkglist_obj);

	if(!luna_service_message_validate_and_send(handle, message, reply_obj))
		luna_service_message_reply_error_internal(handle, message);

	j_release(&reply_obj);
	g_slist_free_full(plistinfo.pkgs, g_free);

	opkg_free();

	return true;
}
static void
rejilla_async_task_manager_insert_task (RejillaAsyncTaskManager *self,
					RejillaAsyncTaskCtx *ctx)
{
	GSList *iter;
	GSList *node;
	RejillaAsyncTaskCtx *tmp;

	node = g_slist_alloc ();
	node->data = ctx;

	if (!self->priv->waiting_tasks) {
		self->priv->waiting_tasks = node;
		return;
	}

	tmp = self->priv->waiting_tasks->data;

	if (tmp->priority < ctx->priority) {
		node->next = self->priv->waiting_tasks;
		self->priv->waiting_tasks = node;
		return;
	}

	for (iter = self->priv->waiting_tasks; iter->next; iter = iter->next) {
		tmp = iter->next->data;

		if (tmp->priority < ctx->priority) {
			node->next = iter->next;
			iter->next = node;
			return;
		}
	}

	iter->next = node;
}
bool service_check_for_update_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	int err = 0;
	struct package_list_info plistinfo;
	GSList *iter;
	jvalue_ref reply_obj = NULL;

	if (opkg_new()) {
		luna_service_message_reply_error_internal(handle, message);
		return true;
	}

	err = opkg_update_package_lists(NULL, NULL);
	if (err != 0) {
		luna_service_message_reply_custom_error(handle, message, "Failed to update package list from configured feeds");
		return true;
	}

	plistinfo.pkgs = g_slist_alloc();
	opkg_list_upgradable_packages(upgradable_package_list_cb, &plistinfo);

	reply_obj = jobject_create();
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("updatesAvailable"),
				jboolean_create(g_slist_length(plistinfo.pkgs) > 0));

	if(!luna_service_message_validate_and_send(handle, message, reply_obj))
		luna_service_message_reply_error_internal(handle, message);

	j_release(&reply_obj);
	g_slist_free_full(plistinfo.pkgs, g_free);

	opkg_free();

	return true;
}
Exemplo n.º 21
0
int main(int argc, char **argv)
{
        SaHpiInt32T         ComputerNumber;  //0..n-1
        SaHpiInt32T         SelectedSystem;  //0..n-1
        SaHpiHsPowerStateT  Action;         
        COMPUTER_DATA       *ComputerPtr;
        SaHpiBoolT          BladeSelected;
        SaHpiBoolT          MultipleBlades;
        SaHpiBoolT          ActionSelected;
        SaHpiBoolT          PrintUsage;
        SaHpiBoolT          DebugPrints;
        GSList*             Computer;
        GSList*             ComputerListHead;
        int                 option;
        SaHpiSessionIdT     SessionId;
        SaErrorT            Status, Clean_Up_Status;
        SaHpiEntryIdT       RptEntry, RptNextEntry;
        SaHpiRptEntryT      Report;
        SaHpiInt32T         Index, EntityElement;
        SaHpiHsPowerStateT  PowerState;
        char                PowerStateString[3][7]={"off\0","on\0","cycled\0"};
        SaHpiVersionT       HpiVersion;

        /*
        // Print out the Program name and Version
        */
        PROGRAM_HEADER;

        /* Set Program Defaults */
        ComputerNumber = 0;
        SelectedSystem = 0;
        Action = 255;  //set it out of range to stand for status
        BladeSelected  = FALSE;
        MultipleBlades = FALSE;
        ActionSelected = FALSE;
        PrintUsage     = FALSE;
        DebugPrints    = FALSE;
        RptEntry       = SAHPI_FIRST_ENTRY;

        /* Parse out option instructions */
        while (1)
        {
                option = getopt(argc, argv, "dpruxb:");
                if ((option == EOF) || (PrintUsage == TRUE))
                {
                break;  //break out of the while loop
                }
                switch (option)
                {
                case 'd':   
                        Action = SAHPI_HS_POWER_OFF;
                        ActionSelected = TRUE;
                break;
                case 'p':   
                        Action = SAHPI_HS_POWER_ON;
                        ActionSelected = TRUE;
                        break;
                case 'r':   
                        Action = SAHPI_HS_POWER_CYCLE;
                        ActionSelected = TRUE;
                        break;
                case 'u':   
                        BladeSelected = TRUE;
                        ActionSelected = TRUE;
                        break;
                case 'x':   
                        DebugPrints = TRUE;
                        break;
                case 'b':   
                        if (*optarg == 0)
                        {
                                PrintUsage = TRUE;
                                break;  //no argument
                        }
                        SelectedSystem = atoi(optarg) - 1;  //Normalizing to 0...n-1
                        if ((SelectedSystem > MAX_MANAGED_SYSTEMS) ||
                            (SelectedSystem < 0))
                        {
                                //Argument is out of Range 
                                PrintUsage = TRUE;
                        }
                        BladeSelected = TRUE;
                        break;
                default:    
                        PrintUsage = TRUE;              
                        break;
                }  //end of switch statement
        } //end of argument parsing while loop

        if (PrintUsage == TRUE)
        {
                UsageMessage(PrgName);
/*BUG:  what is the exit code for bad argument?*/
                exit(0);   //When we exit here, there is nothing to clean up
        }

        /* Initialize the first of a list of computers */

        HPI_POWER_DEBUG_PRINT("1.0 Initializing the List Structure for the computers\n"); 
        Computer = g_slist_alloc();
        ComputerListHead = Computer;
        HPI_POWER_DEBUG_PRINT("1.1 Allocating space for the information on each computer\n");
        ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA));

        Computer->data = (gpointer)ComputerPtr;

        /* Initialize HPI domain and session */
        HPI_POWER_DEBUG_PRINT("2.0 Initalizing HPI\n");
        Status = saHpiInitialize(&HpiVersion);
        if (Status == SA_OK)
        {
                HPI_POWER_DEBUG_PRINT("2.1 Initalizing HPI Session\n");
                Status = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,
                                          &SessionId,
                                          NULL);
        }
        if (Status == SA_OK)
        {
                /* Find all of the individual systems */
                // regenerate the Resource Presence Table(RPT)
                HPI_POWER_DEBUG_PRINT("2.2 Hpi Discovery\n");
                Status = saHpiResourcesDiscover(SessionId);
        }

        HPI_POWER_DEBUG_PRINT("3.0 Walking through all of the Report Tables\n");
        while ((Status == SA_OK) && (RptEntry != SAHPI_LAST_ENTRY))
        {
                HPI_POWER_DEBUG_PRINT("@");
                Status = saHpiRptEntryGet(SessionId,
                                          RptEntry,
                                          &RptNextEntry,
                                          &Report);
                RptEntry = RptNextEntry;

                // Blades will have the first Element of the Entity Path set to SBC_BLADE
                EntityElement = 0;
                HPI_POWER_DEBUG_PRINT(".");
                if (Report.ResourceEntity.Entry[EntityElement].EntityType == 
                    SAHPI_ENT_SBC_BLADE)
                {
                        HPI_POWER_DEBUG_PRINT("#");
                        // We have found a Blade
                        ComputerPtr->ResID = Report.ResourceId;
                        /* enumerate this list as created */
                        ComputerPtr->number = ComputerNumber;
                        ComputerNumber++;
                        ComputerPtr->Instance = 
                                Report.ResourceEntity.Entry[EntityElement].EntityLocation;
                        // find a Name string for this blade
                        sprintf(ComputerPtr->NameStr,
                                "%s %d",
                                (char*)Report.ResourceTag.Data,
                                (int) ComputerPtr->Instance);

                        // Create a new allocation for another system
                        ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA));
                        // Add another member to the list
                        Computer = g_slist_append(Computer,(gpointer)ComputerPtr);
                        // set a flag that we are working with blades
                        MultipleBlades = TRUE;

                }
        }

        HPI_POWER_DEBUG_PRINT("\n4.0 Generating Listing of options to choose from:\n");
        /* If parsed option does not select blade and 
       more than one is found */
        if ((MultipleBlades == TRUE) && (BladeSelected == FALSE) && (Status == SA_OK))
        {
                HPI_POWER_DEBUG_PRINT("4.1 Printing out a listing of all the blades\n");
                for (Index = 0; Index < ComputerNumber; Index++)
                {
                        HPI_POWER_DEBUG_PRINT("$");
                        // obtain the information for this computer
                        ComputerPtr = g_slist_nth_data(ComputerListHead, Index);
                        if (ComputerPtr == NULL)
                        {
                                printf("Call returned a NULL\n");
                                break;
                        }

                        // retrieve the power status for this computer
                        HPI_POWER_DEBUG_PRINT("%%");
                        PowerState = 0;
                        Status = saHpiResourcePowerStateGet(SessionId,
                                                            ComputerPtr->ResID,
                                                            &PowerState);
                        if (Status != SA_OK)
                        {
                                printf("%s does not support PowerStateGet", 
                                       ComputerPtr->NameStr);
                        }

                        /* Print out all of the systems */
                        printf("%2d) %20s  - %s \n\r", (Index + 1), 
                               ComputerPtr->NameStr, 
                               PowerStateString[PowerState]);
                }
                /* Prompt user to select one */
                while ((Index >= ComputerNumber) || (Index < 0))
                {
                        printf("\nEnter the number for the desired blade: ");
                        scanf("%d",&Index);
                        Index--; //normalize to 0..n-1
                        printf("\n");
                }
                BladeSelected = TRUE;
                SelectedSystem = Index;
        }
        HPI_POWER_DEBUG_PRINT("4.2 Generating Listing of Actions to choose from\n");
        /* If action is not selected */
        if ((ActionSelected == FALSE) && (Status == SA_OK))
        {
                /* prompt user to select an action */
                printf("\nSelect Action: 0 - Off; 1 - On; 2 - Reset; 3 - Status \n\r");
                printf("Enter a number 0 to 3:  ");
                scanf("%d", &Index);
                switch (Index)
                {
                case 0:    
                        Action = SAHPI_HS_POWER_OFF;
                        break;
                case 1:     
                        Action = SAHPI_HS_POWER_ON;
                        break;
                case 2:     
                        Action = SAHPI_HS_POWER_CYCLE;
                        break;
                default:    
                        Action = 255;  //Out of Range for "Status"
                        break;
                }
        }
        /* execute the command */

        if (Status == SA_OK)
        {
                HPI_POWER_DEBUG_PRINT("5.0 Executing the command\n\r");
                // obtain the information for this computer
                ComputerPtr = g_slist_nth_data(ComputerListHead, SelectedSystem);

                if (Action <= SAHPI_HS_POWER_CYCLE)
                {
                        HPI_POWER_DEBUG_PRINT("5.1 Setting a New Power State\n\r");
                        // Set the new power status for this computer
                        Status = saHpiResourcePowerStateSet(SessionId,
                                                            ComputerPtr->ResID,
                                                            Action);
                        /* return status */
                        if (Status == SA_OK)
                        {
                                printf("\n%s -- %20s has been successfully powered %s\n",
                                       PrgName, 
                                       ComputerPtr->NameStr, 
                                       PowerStateString[Action]);
                        }
                } 
                else   // Report Power status for the system
                {
                        HPI_POWER_DEBUG_PRINT("5.2 Getting the Power Status\n\r");
                        // retrieve the power status for this computer
                        PowerState = 0;
                        Status = saHpiResourcePowerStateGet(SessionId,
                                                            ComputerPtr->ResID,
                                                            &PowerState);
                        if (Status != SA_OK)
                        {
                                printf("%s does not support PowerStateGet", 
                                       ComputerPtr->NameStr);
                        }

                        /* Print out Status for this system */
                        printf("%2d) %20s  - %s \n\r", (ComputerPtr->number + 1), 
                               ComputerPtr->NameStr, 
                               PowerStateString[PowerState]);
                }
        }
        HPI_POWER_DEBUG_PRINT("6.0 Clean up");
        /* clean up */
        Clean_Up_Status = saHpiSessionClose(SessionId);
        Clean_Up_Status = saHpiFinalize();
        //Free all of the Allocations for the Computer data
        Computer = ComputerListHead;
        while (Computer != NULL)
        {
                free(Computer->data);
                Computer = g_slist_next(Computer);
        }
        //Free the whole List
        g_slist_free(ComputerListHead);

        /* return status code and exit */

        if (Status != SA_OK)
        {
                HPI_POWER_DEBUG_PRINT("7.0 Reporting Bad Status");
                AppHpiPrintError(Status, PrgName);
        }

        return(Status);
}
Exemplo n.º 22
0
int main(int argc, char **argv)
{
    SaHpiInt32T         ComputerNumber = 0;  //0..n-1
    SaHpiInt32T         SelectedSystem = 0;  //0..n-1
    SaHpiPowerStateT    Action = 255;  //set it out of range to stand for status;
    COMPUTER_DATA       *ComputerPtr;
    SaHpiBoolT          BladeSelected  = FALSE;
    SaHpiBoolT          MultipleBlades = FALSE;
    SaHpiBoolT          ActionSelected = FALSE;
    GSList*             Computer;
    GSList*             ComputerListHead;
    SaHpiSessionIdT     SessionId;
    SaErrorT            Status;
    SaHpiEntryIdT       RptEntry = SAHPI_FIRST_ENTRY;
    SaHpiEntryIdT       RptNextEntry;
    SaHpiRptEntryT      Report;
    SaHpiInt32T         Index, EntityElement;
    SaHpiPowerStateT    PowerState;
    char                PowerStateString[3][7]= {"off\0","on\0","cycled\0"};
    GOptionContext      *context;

    /* Print version strings */
    oh_prog_version(argv[0]);

    /* Parsing options */
    static char usetext[]="- Exercise HPI Power Management APIs\n  "
                          OH_SVN_REV;
    OHC_PREPARE_REVISION(usetext);
    context = g_option_context_new (usetext);
    g_option_context_add_main_entries (context, my_options, NULL);

    if (!ohc_option_parse(&argc, argv,
                          context, &copt,
                          OHC_ALL_OPTIONS
                          - OHC_ENTITY_PATH_OPTION //TODO: Feature 880127
                          - OHC_VERBOSE_OPTION )) {    // no verbose mode implemented
        g_option_context_free (context);
        return 1;
    }
    g_option_context_free (context);
    if (f_down) {
        Action = SAHPI_POWER_OFF;
        ActionSelected = TRUE;
    }
    if (f_up) {
        Action = SAHPI_POWER_ON;
        ActionSelected = TRUE;
    }
    if (f_reset) {
        Action = SAHPI_POWER_CYCLE;
        ActionSelected = TRUE;
    }
    if (f_unattended) {
        BladeSelected = TRUE;
        ActionSelected = TRUE;
    }
    if (f_blade > 0) {
        BladeSelected = TRUE;
        SelectedSystem = f_blade - 1;  //Normalizing to 0...n-1
        if ((SelectedSystem > MAX_MANAGED_SYSTEMS) ||
                (SelectedSystem < 0)) {
            CRIT("hpipower: blade number out of range");
            return 1;   //When we exit here, there is nothing to clean up
        }
    }


    /* Initialize the first of a list of computers */

    HPI_POWER_DEBUG_PRINT("Initializing the List Structure for the computers");
    Computer = g_slist_alloc();
    ComputerListHead = Computer;

    HPI_POWER_DEBUG_PRINT("Allocating space for the information on each computer");
    ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA));

    Computer->data = (gpointer)ComputerPtr;

    /* Initialize HPI domain and session */
    HPI_POWER_DEBUG_PRINT("Initalizing HPI Session");
    Status = ohc_session_open_by_option ( &copt, &SessionId);
    if (Status == SA_OK)
    {
        /* Find all of the individual systems */
        // regenerate the Resource Presence Table(RPT)
        HPI_POWER_DEBUG_PRINT("Hpi Discovery");
        Status = saHpiDiscover(SessionId);
    } else {
        CRIT("Initalizing HPI Session FAILED, code %s", oh_lookup_error(Status));
        return -1;
    }

    HPI_POWER_DEBUG_PRINT("Walking through all of the Report Tables");
    while ((Status == SA_OK) && (RptEntry != SAHPI_LAST_ENTRY))
    {
        HPI_POWER_DEBUG_PRINT1("@");
        Status = saHpiRptEntryGet(SessionId,
                                  RptEntry,
                                  &RptNextEntry,
                                  &Report);
        RptEntry = RptNextEntry;

        // Blades will have the first Element of the Entity Path set to SBC_BLADE
        EntityElement = 0;
        HPI_POWER_DEBUG_PRINT1(".");
        if (Report.ResourceCapabilities & SAHPI_CAPABILITY_POWER)
        {
            char tagbuf[SAHPI_MAX_TEXT_BUFFER_LENGTH + 1];

            HPI_POWER_DEBUG_PRINT1("#");
            // We have found a Blade
            ComputerPtr->ResID = Report.ResourceId;
            /* enumerate this list as created */
            ComputerPtr->number = ComputerNumber;
            ComputerNumber++;
            ComputerPtr->Instance =
                Report.ResourceEntity.Entry[EntityElement].EntityLocation;
            // find a Name string for this blade
            HpiTextBuffer2CString( &Report.ResourceTag, tagbuf );
            snprintf(ComputerPtr->NameStr, sizeof(ComputerPtr->NameStr),
                     "%s %d",
                     tagbuf,
                     (int) ComputerPtr->Instance);

            // Create a new allocation for another system
            ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA));
            // Add another member to the list
            Computer = g_slist_append(Computer,(gpointer)ComputerPtr);
            // set a flag that we are working with blades
            MultipleBlades = TRUE;

        }
    }

    HPI_POWER_DEBUG_PRINT("Generating Listing of options to choose from:");
    /* If parsed option does not select blade and
    more than one is found */
    if ((MultipleBlades == TRUE) && (BladeSelected == FALSE) && (Status == SA_OK))
    {
        HPI_POWER_DEBUG_PRINT("Printing out a listing of all the blades");
        for (Index = 0; Index < ComputerNumber; Index++)
        {
            HPI_POWER_DEBUG_PRINT1("$");
            // obtain the information for this computer
            ComputerPtr = g_slist_nth_data(ComputerListHead, Index);
            if (ComputerPtr == NULL)
            {
                printf("Call returned a NULL\n");
                break;
            }

            // retrieve the power status for this computer
            HPI_POWER_DEBUG_PRINT1("%%");
            PowerState = 0;
            Status = saHpiResourcePowerStateGet(SessionId,
                                                ComputerPtr->ResID,
                                                &PowerState);
            if (Status != SA_OK)
            {
                printf("%s does not support PowerStateGet",
                       ComputerPtr->NameStr);
            }

            /* Print out all of the systems */
            printf("%2d) %20s  - %s \n\r", (Index + 1),
                   ComputerPtr->NameStr,
                   PowerStateString[PowerState]);
        }
        /* Prompt user to select one */
        while ((Index >= ComputerNumber) || (Index < 0))
        {
            printf("\nEnter the number for the desired blade: ");
            if (scanf("%d",&Index) == 0) {
                printf("Incorrect number\n");
            }
            Index--; //normalize to 0..n-1
            printf("\n");
        }
        BladeSelected = TRUE;
        SelectedSystem = Index;
    }
    HPI_POWER_DEBUG_PRINT("Generating Listing of Actions to choose from");
    /* If action is not selected */
    if ((ActionSelected == FALSE) && (Status == SA_OK))
    {
        /* prompt user to select an action */
        printf("\nSelect Action: 0 - Off; 1 - On; 2 - Reset; 3 - Status \n\r");
        printf("Enter a number 0 to 3:  ");
        if (scanf("%d", &Index) == 0) {
            Index = -1;
        }
        switch (Index)
        {
        case 0:
            Action = SAHPI_POWER_OFF;
            break;
        case 1:
            Action = SAHPI_POWER_ON;
            break;
        case 2:
            Action = SAHPI_POWER_CYCLE;
            break;
        default:
            Action = 255;  //Out of Range for "Status"
            break;
        }
    }
    /* execute the command */

    if (Status == SA_OK)
    {
        HPI_POWER_DEBUG_PRINT("Executing the command");
        // obtain the information for this computer
        ComputerPtr = g_slist_nth_data(ComputerListHead, SelectedSystem);
        if (ComputerPtr == NULL)
        {
            printf("Error: Selected system %d was not found.\n", SelectedSystem);
            return -1;
        }

        if (Action <= SAHPI_POWER_CYCLE)
        {
            HPI_POWER_DEBUG_PRINT("Setting a New Power State");
            // Set the new power status for this computer
            Status = saHpiResourcePowerStateSet(SessionId,
                                                ComputerPtr->ResID,
                                                Action);
            /* return status */
            if (Status == SA_OK)
            {
                printf("\n%s -- %20s has been successfully powered %s\n",
                       argv[0],
                       ComputerPtr->NameStr,
                       PowerStateString[Action]);
            }
        }
        else   // Report Power status for the system
        {
            HPI_POWER_DEBUG_PRINT("Getting the Power Status\r");
            // retrieve the power status for this computer
            PowerState = 0;
            Status = saHpiResourcePowerStateGet(SessionId,
                                                ComputerPtr->ResID,
                                                &PowerState);
            if (Status != SA_OK)
            {
                printf("%s does not support PowerStateGet",
                       ComputerPtr->NameStr);
            }

            /* Print out Status for this system */
            printf("%2d) %20s  - %s \n\r", (ComputerPtr->number + 1),
                   ComputerPtr->NameStr,
                   PowerStateString[PowerState]);
        }
    }
    HPI_POWER_DEBUG_PRINT("Clean up");
    /* clean up */
    saHpiSessionClose(SessionId);

    //Free all of the Allocations for the Computer data
    Computer = ComputerListHead;
    while (Computer != NULL)
    {
        free(Computer->data);
        Computer = g_slist_next(Computer);
    }
    //Free the whole List
    g_slist_free(ComputerListHead);

    /* return status code and exit */

    if (Status != SA_OK)
    {
        HPI_POWER_DEBUG_PRINT("Reporting Bad Status");
        CRIT("Error: %s", oh_lookup_error(Status));
    }

    return(Status);
}
Exemplo n.º 23
0
void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
                  gpointer user_data) {
  struct att_data_list *list   = NULL;
  guint8                format;
  uint16_t              handle = 0xffff;
  int                   i;
  char                  uuid_str[MAX_LEN_UUID_STR];
  uint8_t              *value;

  printf_dbg("[CB] IN char_desc_cb\n");
  if (status) {
    cb_ret_val = BL_REQUEST_FAIL_ERROR;
    sprintf(cb_ret_msg, "Characteristic descriptor "
        "callback: Failure: %s\n", att_ecode2str(status));
    goto exit;
  }

  list = dec_find_info_resp(pdu, plen, &format);
  if (list == NULL) {
    cb_ret_val = BL_NO_ERROR;
    strcpy(cb_ret_msg, "Characteristic descriptor callback: Nothing found\n");
    goto exit;
  }

  for (i = 0; i < list->num; i++) {
    bt_uuid_t uuid;

    value = list->data[i];
    handle = att_get_u16(value);

    if (format == 0x01)
      uuid = att_get_uuid16(&value[2]);
    else
      uuid = att_get_uuid128(&value[2]);

    bt_uuid_to_string(&uuid, uuid_str, MAX_LEN_UUID_STR);
    if (strcmp(uuid_str, GATT_PRIM_SVC_UUID_STR) &&
        strcmp(uuid_str, GATT_SND_SVC_UUID_STR)  &&
        strcmp(uuid_str, GATT_INCLUDE_UUID_STR)  &&
        strcmp(uuid_str, GATT_CHARAC_UUID_STR)) {
      bl_desc_t *bl_desc = bl_desc_new(uuid_str, handle);
      if (bl_desc == NULL) {
        cb_ret_val = BL_MALLOC_ERROR;
        strcpy(cb_ret_msg, "Characteristic descriptor callback: Malloc "
            "error\n");
        goto exit;
      }
      if (bl_desc_list == NULL) {
        bl_desc_list = g_slist_alloc();
        if (bl_desc_list == NULL) {
          cb_ret_val = BL_MALLOC_ERROR;
          strcpy(cb_ret_msg, "Characteristic descriptor callback: Malloc "
              "error\n");
          goto exit;
        }
        bl_desc_list->data = bl_desc;
      } else {
        bl_desc_list = g_slist_append(bl_desc_list, bl_desc);
      }
    } else {
      printf_dbg("Reach end of descriptor list\n");
      goto exit;
    }
  }
  if ((handle != 0xffff) && (handle < end_handle_cb)) {
    printf_dbg("[CB] OUT with asking for a new request\n");
    if (gatt_discover_char_desc(attrib, handle + 1, end_handle_cb,
          char_desc_cb, NULL)) {
      goto next;
    }
    cb_ret_val = BL_SEND_REQUEST_ERROR;
    strcpy(cb_ret_msg, "Unable to send request\n");
  }

exit:
  if (bl_desc_list) {
    // Return what we got if we add something
    cb_ret_val = BL_NO_ERROR;
    cb_ret_pointer = bl_desc_list;
  }
  bl_desc_list = NULL;
  g_mutex_unlock(pending_callback);
next:
  if (list)
    att_data_list_free(list);
  printf_dbg("[CB] OUT char_desc_cb\n");
}
Exemplo n.º 24
0
/******************************************************************
 Display the mail
*******************************************************************/
static int read_window_display_mail(struct Read_Data *data, struct mail *m)
{
	char path[512];

	if (!data->folder_path) return 0;

	data->ref_mail = m;

	getcwd(path,sizeof(path));
	if (chdir(data->folder_path)==-1) return 0;

	if ((data->mail = mail_create_from_file(m->filename)))
	{
		int dont_show = 0; /* attachments */
		chdir(path); /* should be a absolute path */
		mail_read_contents(data->folder_path,data->mail);
		mail_create_html_header(data->mail, 0);

		if (!data->mail->num_multiparts || (data->mail->num_multiparts == 1 && !data->mail->multipart_array[0]->num_multiparts))
		{
			/* mail has only one part */
			dont_show = 1;
		} else
		{
		}

		if (data->mail_list) g_slist_free(data->mail_list);
		data->mail_list = g_slist_alloc();

		insert_mail(data,data->mail);
		show_mail(data,mail_find_initial(data->mail));
	} else chdir(path);

	return 1;

	#if 0

	if ((lock = Lock(data->folder_path,ACCESS_READ))) /* maybe it's better to use an absoulte path here */
	{
		BPTR old_dir = CurrentDir(lock);

		if ((data->mail = mail_create_from_file(mail->filename)))
		{
			int dont_show = 0;
			mail_read_contents(data->folder_path,data->mail);
			mail_create_html_header(data->mail);

			if (!data->mail->num_multiparts || (data->mail->num_multiparts == 1 && !data->mail->multipart_array[0]->num_multiparts))
			{
				/* mail has only one part */
				set(data->attachments_group, MUIA_ShowMe, FALSE);
				dont_show = 1;
			} else
			{
				DoMethod((Object*)xget(data->attachments_group,MUIA_Parent), MUIM_Group_InitChange);
			}

			DoMethod(data->attachments_group, MUIM_Group_InitChange);
			DisposeAllChilds(data->attachments_group);
			data->attachments_last_selected = NULL;
			insert_mail(data,data->mail);
			DoMethod(data->attachments_group, OM_ADDMEMBER, HSpace(0));
			DoMethod(data->attachments_group, MUIM_Group_ExitChange);

			if (!dont_show)
			{
				set(data->attachments_group, MUIA_ShowMe, TRUE);
				DoMethod((Object*)xget(data->attachments_group,MUIA_Parent), MUIM_Group_ExitChange);
			}

			show_mail(data,mail_find_initial(data->mail));

			CurrentDir(old_dir);
			set(App, MUIA_Application_Sleep, FALSE);
			return 1;
		}
		CurrentDir(old_dir);
	}

	DoMethod(data->attachments_group, MUIM_Group_InitChange);
	DisposeAllChilds(data->attachments_group);
	data->attachments_last_selected = NULL;
	DoMethod(data->attachments_group, OM_ADDMEMBER, HSpace(0));
	DoMethod(data->attachments_group, MUIM_Group_ExitChange);
	set(App, MUIA_Application_Sleep, FALSE);
	return 0;
	#endif
}
Exemplo n.º 25
0
static void parseScores(char *buf, int len)
{ /* read string buffer and make adequate 'currentScores' structure */
  char *ptr = buf;
  char *end = buf+len;
  
#define isWhitespace(c) (c==' '||c=='\t')

  currentScores = g_slist_alloc();
  
  while (ptr<end) 
    {
      switch(*ptr) {
      case ' ':
      case '\t':
      case '\n':
	ptr++;
	break;
      case '#':
	{
	  while(*ptr!='\n') { ++ptr; }
	  ptr++;
	  break;
	}
      default:
	{
	  int l;
	  char *n, *s, *p = ptr;
	  
	  while(!(isWhitespace(*p)) && *p!='\n') { p++; }
	  l = p-ptr;
	  n = (char*)g_malloc(sizeof(char)*l);
	  strncpy(n,ptr,l);
	  n[l]='\0';
	  while(isWhitespace(*p)) { p++; }
	  ptr = p;
	  while(!(isWhitespace(*p)) && *p!='\n') { p++; }
	  l = p-ptr;
	  s = (char*)g_malloc(sizeof(char)*l);
	  strncpy(s,ptr,l);
	  s[l]='\0';
	  ptr = p;

	  DEBUG(("\t '%s'-->'%s'\n",n,s));
	  {
	    ScoreRecord *record;
	    
	    record = (ScoreRecord*)g_malloc(sizeof(ScoreRecord));
	    record->name  = n;
	    record->score = s;
	    
	    currentScores = g_slist_append(currentScores,record);
	  }
	}
      }
    }
 DONE:
}

void readScores(char *scorefile)
{
  if(scorefile!=(char*)NULL)
    {
      char *buf;
      struct stat sb;
      FILE *file = fopen(scorefile,"r");
      
      currentScoresFile = scorefile;
      {
	/*if(stat(scorefile,&sb)==0) /* could use fstat(fileno(file),&sb) instead */
	if(fstat(fileno(file),&sb)!=0)
	  {
	    printf("can't stat file '%s'!\n",scorefile);
	    exit(EXIT_FAILURE);
	  }
      }
      {
	buf = (char*)g_malloc(sizeof(char)*(sb.st_size+1));
	if(buf==NULL)
	  {
	    printf("can't malloc memory!\n");
	    exit(EXIT_FAILURE);
	  }
	(void)fread(buf,sb.st_size,1,file);
	parseScores(buf,sb.st_size);
      }
      fclose(file);
    }
}

void saveScores(GSList *rec, char *filename)
{
  FILE *file;
  
  if(filename==(char*)NULL)
    filename = currentScoresFile;
  if(filename==(char*)NULL)
    filename = "~/.gms-scores";
  if(strcasecmp(filename,"stdout"))
    file = stdout;
  else
    file = fopen(filename,"w"); /* replace the contents of this file ! */
  if(file==(FILE*)NULL)
    {
      char *msg;
      
      msg = (char*)g_malloc(sizeof(char)*(strlen(filename)+20));
      sprintf(msg,"Can't open file '%s'",filename);
      ModalInfoBox(msg,"Error!");
      g_free(msg);
      return;
    }
  
  fprintf(file,"# File generated by "NAME", do not edit!\n");
  {
#if 0
    ScoreRecord *r = rec;
    while(r!=(ScoreRecord*)NULL)
      {
	fprintf(file,"%s\t%s\n",r->name,r->score);
	r++;
      }
#else
    GSList *lst = rec;
    while(lst = g_slist_next(lst)) 
      {
	ScoreRecord *record = (ScoreRecord*)lst->data;
	fprintf(file,"%s\t%s\n",record->name,record->score);
      }
#endif
  }
  fclose(file);
}
Exemplo n.º 26
0
/*
 * Create quit dialog
 */
gboolean av_dialog_quit_new(const GPtrArray *list, guint list_len)
{
  GSList *chkbtn_list = NULL, *filelist = NULL;
  GtkWidget *content_area = NULL;
  gboolean quit_status = TRUE;
  gint result = 0;

  /* Create quit dialog */
  main_widget.dialog_quit = gtk_dialog_new();

  /* Set window title */
  gtk_window_set_title(GTK_WINDOW(main_widget.dialog_quit), AV_WIDGET_QUIT_DIALOG_TITLE);

  /* Set window position */
  gtk_window_set_position(GTK_WINDOW(main_widget.dialog_quit), GTK_WIN_POS_CENTER);

  /* Set as resizable window */
  gtk_window_set_resizable(GTK_WINDOW(main_widget.dialog_quit), FALSE);

  /* Get content area in dialog */
  content_area = gtk_dialog_get_content_area(GTK_DIALOG(main_widget.dialog_quit));

  /* Create check-button widgets list */
  chkbtn_list = dialog_chkbtn_list_new(content_area, list, list_len);

  /* Create buttons in dialog */
  if (NULL == chkbtn_list)
  {
    gtk_dialog_add_buttons(GTK_DIALOG(main_widget.dialog_quit),
                           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                           GTK_STOCK_OK, GTK_RESPONSE_OK,
                           NULL);
  }
  else
  {
    gtk_dialog_add_buttons(GTK_DIALOG(main_widget.dialog_quit),
                           AV_WIDGET_BUTTONS_CLOSE_WITHOUT_SAVING, AV_RESPONSE_CLOSE_WITHOUT_SAVING,
                           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                           GTK_STOCK_SAVE, AV_RESPONSE_SAVE,
                           NULL);
  }

  result = gtk_dialog_run(GTK_DIALOG(main_widget.dialog_quit));
  switch (result)
  {
    case GTK_RESPONSE_CANCEL:
      AV_DBG("%s: canceled\n", __func__);
      gtk_widget_destroy(main_widget.dialog_quit);
      return FALSE;
    case GTK_RESPONSE_OK:
      AV_DBG("%s: closed only\n", __func__);
      break;
    case AV_RESPONSE_CLOSE_WITHOUT_SAVING:
      AV_DBG("%s: closed without saving\n", __func__);
      break;
    case AV_RESPONSE_SAVE:
      AV_DBG("%s: closed and saved\n", __func__);
      filelist = g_slist_alloc();
      g_slist_foreach(chkbtn_list, (GFunc)dialog_chkbtn_list_active_new, &filelist);
      av_doc_save_filelist(filelist);
      break;
    default:
      quit_status = FALSE;
      break;
  }

  /* Free file selected list in check-button list */
  dialog_chkbtn_list_active_del(filelist);

  /* Free check-button widgets list */
  dialog_chkbtn_list_del(chkbtn_list);

  /* All widgets will be destroyed by 'main_quit' */
  av_main_quit();

  return quit_status;
}
Exemplo n.º 27
0
static GSList *insert_new_accelcand(GSList * list, float power, float sigma,
                                    int numharm, double rr, double zz, int *added)
/* Checks the current list to see if there is already */
/* a candidate within ACCEL_CLOSEST_R bins.  If not,  */
/* it adds it to the list in increasing freq order.   */
{
   GSList *tmp_list = list, *prev_list = NULL, *new_list;
   double prev_diff_r = ACCEL_CLOSEST_R + 1.0, next_diff_r;

   *added = 0;
   if (!list) {
      new_list = g_slist_alloc();
      new_list->data = (gpointer *) create_accelcand(power, sigma, numharm, rr, zz);
      *added = 1;
      return new_list;
   }

   /* Find the correct position in the list for the candidate */

   while ((tmp_list->next) && (((accelcand *) (tmp_list->data))->r < rr)) {
      prev_list = tmp_list;
      tmp_list = tmp_list->next;
   }
   next_diff_r = fabs(rr - ((accelcand *) (tmp_list->data))->r);
   if (prev_list)
      prev_diff_r = fabs(rr - ((accelcand *) (prev_list->data))->r);

   /* Similar candidate(s) is(are) present */

   if (prev_diff_r < ACCEL_CLOSEST_R) {
      /* Overwrite the prev cand */
      if (((accelcand *) (prev_list->data))->sigma < sigma) {
         free_accelcand(prev_list->data, NULL);
         prev_list->data = (gpointer *) create_accelcand(power, sigma,
                                                         numharm, rr, zz);
         *added = 1;
      }
      if (next_diff_r < ACCEL_CLOSEST_R) {
         if (((accelcand *) (tmp_list->data))->sigma < sigma) {
            free_accelcand(tmp_list->data, NULL);
            if (*added) {
               /* Remove the next cand */
               list = g_slist_remove_link(list, tmp_list);
               g_slist_free_1(tmp_list);
            } else {
               /* Overwrite the next cand */
               tmp_list->data = (gpointer *) create_accelcand(power, sigma,
                                                              numharm, rr, zz);
               *added = 1;
            }
         }
      }
   } else if (next_diff_r < ACCEL_CLOSEST_R) {
      /* Overwrite the next cand */
      if (((accelcand *) (tmp_list->data))->sigma < sigma) {
         free_accelcand(tmp_list->data, NULL);
         tmp_list->data = (gpointer *) create_accelcand(power, sigma,
                                                        numharm, rr, zz);
         *added = 1;
      }
   } else {                     /* This is a new candidate */
      new_list = g_slist_alloc();
      new_list->data = (gpointer *) create_accelcand(power, sigma, numharm, rr, zz);
      *added = 1;
      if (!tmp_list->next &&
          (((accelcand *) (tmp_list->data))->r < (rr - ACCEL_CLOSEST_R))) {
         tmp_list->next = new_list;
         return list;
      }
      if (prev_list) {
         prev_list->next = new_list;
         new_list->next = tmp_list;
      } else {
         new_list->next = list;
         return new_list;
      }
   }
   return list;
}
Exemplo n.º 28
0
struct audio_service* audio_service_create()
{
	struct audio_service *service;
	LSError error;
	pa_mainloop_api *mainloop_api;
	char name[100];

	service = g_try_new0(struct audio_service, 1);
	if (!service)
		return NULL;

	LSErrorInit(&error);

	if (!LSRegisterPubPriv("org.webosports.audio", &service->handle, false, &error)) {
		g_warning("Failed to register the luna service: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSRegisterCategory(service->handle, "/", audio_service_methods,
			NULL, NULL, &error)) {
		g_warning("Could not register service category: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSCategorySetData(service->handle, "/", service, &error)) {
		g_warning("Could not set daa for service category: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSGmainAttach(service->handle, event_loop, &error)) {
		g_warning("Could not attach service handle to mainloop: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	service->pa_mainloop = pa_glib_mainloop_new(g_main_context_default());
	mainloop_api = pa_glib_mainloop_get_api(service->pa_mainloop);

	snprintf(name, 100, "AudioServiceContext:%i", getpid());
	service->context = pa_context_new(mainloop_api, name);
	service->context_initialized = false;
	pa_context_set_state_callback(service->context, context_state_cb, service);

	if (pa_context_connect(service->context, NULL, 0, NULL) < 0) {
		g_warning("Failed to connect to PulseAudio");
		pa_context_unref(service->context);
		pa_glib_mainloop_free(service->pa_mainloop);
		goto error;
	}

	sample_list = g_slist_alloc();

	return service;

error:
	if (service->handle != NULL) {
		LSUnregister(service->handle, &error);
		LSErrorFree(&error);
	}

	g_free(service);

	return NULL;
}