Exemplo n.º 1
0
void RFM70::setModeRX(void) {
	uint8_t val;

	// Flush RX FIFO
	spiSend(0, (uint8_t *) RFM70_cmd_flush_rx, NELEMS(RFM70_cmd_flush_rx));
	// Read Status
	val = readRegVal(RFM70_REG_STATUS);
	// Reset IRQ bits
	uint8_t data[] = {RFM70_CMD_WRITE_REG | RFM70_REG_STATUS, val};
	spiSend(0, data, 2);
	// RFM chip disable
	digitalWrite(_ce, LOW);
	// set PRIM_RX bit to 1
	val = readRegVal(RFM70_REG_CONFIG);
	val |= RFM70_PIN_PRIM_RX;
	data[0] = RFM70_CMD_WRITE_REG | RFM70_REG_CONFIG;
	data[1] = val;
	spiSend(0, data, 2);
	// RFM chip enable
	digitalWrite(_ce, HIGH);
}
Exemplo n.º 2
0
static void
recv_stop(Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg) {
    Call *c = (Call *) obj;
    int index;

    assert(et == EV_CALL_RECV_STOP && object_is_call(c));
    assert(c->basic.time_recv_start > 0);

    basic.call_xfer_sum += timer_now() - c->basic.time_recv_start;

    basic.hdr_bytes_received += c->reply.header_bytes;
    basic.reply_bytes_received += c->reply.content_bytes;
    basic.footer_bytes_received += c->reply.footer_bytes;

    index = (c->reply.status / 100);
    assert((unsigned) index < NELEMS(basic.num_replies));
    ++basic.num_replies[index];
    ++num_replies;

    ++c->conn->basic.num_calls_completed;
}
Exemplo n.º 3
0
void Atom_free(const char *str)
{
	unsigned long h;
	unsigned long hash_number;
	struct atom *p;
	struct atom *c;
	int Len;

	assert(str);

	Len = strlen(str);

	//Cercare atomo con la stringa
	hash_number = Atom_CalculateHash(str, Len);
	h = hash_number % NELEMS(buckets);
#ifdef DEBUG
	fprintf(stderr, "Hash number for string %s => %ld\n", str, hash_number);
	fprintf(stderr, "Hash value for string %s => %ld\n", str, h);
#endif

	c = buckets[h];
	p = NULL;
	/* Se due stringhe hanno un hash_number uguale, significa che corrispondono
	 * */
	while( c && (hash_number != c->hash_number) )
	{
		p = c;
		c = c->link;
	}

	if( p == NULL )
	{
		buckets[h] = c->link;
	}
	else
	{
		p->link = c->link;
	}
    FREE(c);
}
Exemplo n.º 4
0
static void
set_debug_level(void)
{
    char *ccspDbg;
    int i;
    struct {
        char *name;
        int level;
    } levelTab[] = {
        {"debug",       CCSP_TRACE_LEVEL_DEBUG, },
        {"info",        CCSP_TRACE_LEVEL_INFO, },
        {"notice",      CCSP_TRACE_LEVEL_NOTICE, },
        {"warning",     CCSP_TRACE_LEVEL_WARNING, },
        {"error",       CCSP_TRACE_LEVEL_ERROR, },
        {"critical",    CCSP_TRACE_LEVEL_CRITICAL, },
        {"alert",       CCSP_TRACE_LEVEL_ALERT, },
        {"emergency",   CCSP_TRACE_LEVEL_EMERGENCY, },
    };

            pComponentName = "CCSP_SNMNP_Plugin";

    ccspDbg = getenv("CCSPDBG");
    if (!ccspDbg)
        return;

    for (i = 0; i < NELEMS(levelTab); i++)
    {
        if (AnscEqualString(ccspDbg, levelTab[i].name, TRUE))
        {
            AnscSetTraceLevel(levelTab[i].level);
            //pComponentName = "CCSP_SNMNP_Plugin";

            AnscTraceWarning(("setting debug level to \"%s\"\n", levelTab[i].name));
            break;
        }
    }

    return;
}
Exemplo n.º 5
0
	LONG WINAPI OnUnhandledException(PEXCEPTION_POINTERS pExceptionInfo)
	{
		if (!bPassOn) // exception occurred while closing, force kill the server
			ExitProcess(1);

		bPassOn = false;

		MINIDUMP_EXCEPTION_INFORMATION ei;
		ei.ExceptionPointers = pExceptionInfo;
		ei.ThreadId = GetCurrentThreadId();
		ei.ClientPointers = FALSE;

		DWORD dwProcessId = GetCurrentProcessId();
		SYSTEMTIME stLocalTime;
		GetLocalTime(&stLocalTime);
		wchar_t CrashDumpW[1024];
		swprintf_s(CrashDumpW, NELEMS(CrashDumpW), 
				L"%s\\%s-%s-%s-%04X-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp", 
				g_CrashDirectory.c_str(), L"Phasor", PHASOR_HALO_BUILD,
				PHASOR_MAJOR_VERSION_STR, 
				PHASOR_INTERNAL_VERSION, stLocalTime.wYear, stLocalTime.wMonth,
				stLocalTime.wDay, stLocalTime.wHour, stLocalTime.wMinute, 
				stLocalTime.wSecond, dwProcessId, ei.ThreadId);

		HANDLE hFile = CreateFileW(CrashDumpW, GENERIC_READ | GENERIC_WRITE,
			NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

#ifdef BUILD_DEBUG
		MINIDUMP_TYPE dwDumpType = MiniDumpWithFullMemory;
#else
		MINIDUMP_TYPE dwDumpType = MiniDumpScanMemory;
#endif

		MiniDumpWriteDump(GetCurrentProcess(), dwProcessId, hFile, 
			dwDumpType, &ei, NULL, NULL);
		CloseHandle(hFile);

		return EXCEPTION_EXECUTE_HANDLER;
	}
Exemplo n.º 6
0
void AllocateLightingPreviewtextures(void)
{
	static bool bHaveAllocated=false;
	if (! bHaveAllocated )
	{
		bHaveAllocated = true;
		MaterialSystemInterface()->BeginRenderTargetAllocation();
		for(int idx=0;idx<NELEMS(sg_ExtraFP16Targets);idx++)
			sg_ExtraFP16Targets[idx].Init(
				materials->CreateNamedRenderTargetTextureEx2(
					s_rt_names[idx],
					512, 512, RT_SIZE_DEFAULT, s_rt_formats[idx],
					MATERIAL_RT_DEPTH_SHARED, 
					TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
					CREATERENDERTARGETFLAGS_HDR )
				);
		
		// End block in which all render targets should be allocated (kicking off an Alt-Tab type
		// behavior)
		MaterialSystemInterface()->EndRenderTargetAllocation();
	}
}
Exemplo n.º 7
0
void CASW_Briefing::AutoSelectFullSquadForSingleplayer( int nFirstSelectedProfileIndex )
{
	if ( !MarineProfileList() )
		return;

	CASW_Marine_Profile* pFirstSelectedProfile = MarineProfileList()->GetProfile( nFirstSelectedProfileIndex );
	if ( !pFirstSelectedProfile )
		return;

	ASW_Marine_Class nMarineClasses[]=
	{
		MARINE_CLASS_NCO, 
		MARINE_CLASS_SPECIAL_WEAPONS,
		MARINE_CLASS_MEDIC,
		MARINE_CLASS_TECH
	};

	// select one of each class
	for ( int i = 0; i < NELEMS( nMarineClasses ); i++ )
	{
		if ( nMarineClasses[ i ] == pFirstSelectedProfile->GetMarineClass() )
			continue;

		CASW_Marine_Profile* pProfile = NULL;
		for ( int p = 0; p < MarineProfileList()->m_NumProfiles; p++ )
		{
			pProfile = MarineProfileList()->GetProfile( p );
			if ( pProfile && pProfile->GetMarineClass() == nMarineClasses[i] )
			{
				break;
			}
		}

		if ( !pProfile )
			continue;

		SelectMarine( 0, pProfile->m_ProfileIndex, -1 );
	}
}
Exemplo n.º 8
0
static unsigned int
elf_x86_x86_map_reloc_info_to_type(elf_reloc_entry *reloc,
                                   yasm_symrec **ssyms)
{
    if (reloc->wrt) {
        size_t i;
        for (i=0; i<NELEMS(elf_x86_x86_ssyms); i++) {
            if (reloc->wrt == ssyms[i] &&
                reloc->valsize == elf_x86_x86_ssyms[i].size) {
                /* Force TLS type; this is required by the linker. */
                if (elf_x86_x86_ssyms[i].sym_rel & ELF_SSYM_THREAD_LOCAL) {
                    elf_symtab_entry *esym;

                    esym = yasm_symrec_get_data(reloc->reloc.sym,
                                                &elf_symrec_data);
                    if (esym)
                        esym->type = STT_TLS;
                }
                return (unsigned char) elf_x86_x86_ssyms[i].reloc;
            }
        }
        yasm_internal_error(N_("Unsupported WRT"));
    } else if (reloc->rtype_rel) {
        switch (reloc->valsize) {
            case 8: return (unsigned char) R_386_PC8;
            case 16: return (unsigned char) R_386_PC16;
            case 32: return (unsigned char) R_386_PC32;
            default: yasm_internal_error(N_("Unsupported relocation size"));
        }
    } else {
        switch (reloc->valsize) {
            case 8: return (unsigned char) R_386_8;
            case 16: return (unsigned char) R_386_16;
            case 32: return (unsigned char) R_386_32;
            default: yasm_internal_error(N_("Unsupported relocation size"));
        }
    }
    return 0;
}
Exemplo n.º 9
0
static error test_rename(atom_set_t *d)
{
  error err;
  int   i;

  printf("test: rename\n");

  for (i = 0; i < NELEMS(newnames); i++)
  {
    atom_t idx;

    printf("adding '%s'... ", data[i]);

    err = atom_new(d, (const unsigned char *) data[i],
                   strlen(data[i]) + 1, &idx);
    if (err && err != error_ATOM_NAME_EXISTS)
      return err;

    if (err == error_ATOM_NAME_EXISTS)
      printf("already exists ");

    printf("as %d\n", idx);

    printf("renaming index %d to '%s'... ", idx, newnames[i]);

    err = atom_set(d, idx, (const unsigned char *) newnames[i],
                   strlen(newnames[i]) + 1);
    if (err == error_ATOM_NAME_EXISTS)
      printf("already exists!");
    else if (err)
      return err;
    else
      printf("ok");

    printf("\n");
  }

  return error_OK;
}
Exemplo n.º 10
0
int uninstall_cfw(void)
{
	int ret;

	sceIoRemove("flash1:/config.se");

	int i; for(i=0; i<NELEMS(g_file_lists); ++i) {
		printf("Removing %s...", g_file_lists[i].dst);
		ret = sceIoRemove(g_file_lists[i].dst);

		if(ret == 0 || ret == 0x80010002) {
			printf("OK\n");
		} else {
			printf("failed(0x%08X)\n", ret);
		}
	}

	// per model uninstall goes here:
	switch(psp_model) {
		case PSP_GO:
			break;
		case PSP_4000:
			break;
		case PSP_3000:
			break;
		case PSP_2000:
			break;
		case PSP_1000:
			break;
	}

	if(is_permanent_patch_installed()) {
		printf("Uninstalling permanent patch...");
		uninstall_permanent_patch();
		printf("OK\n");
	}

	return 0;
}
Exemplo n.º 11
0
static error test_add_tags(State *state)
{
  error err;
  int   i;

  for (i = 0; i < NELEMS(tagnames); i++)
  {
    printf("adding '%s'...", tagnames[i]);
    err = tagdb_add(state->db, tagnames[i], &state->tags[i]);
    if (err)
      goto Failure;

    printf("is tag %d\n", state->tags[i]);
  }

  return error_OK;


Failure:

  return err;
}
Exemplo n.º 12
0
int simulate_files(int creat)
{
	size_t i;
	char *files[] =
	    { "config0.cfg", "config1.cfg", "config2.cfg", "config3.cfg",
		"rr109.img", "rx100.img", "rx107.img", "rm957.img", "messages"
	};

	for (i = 0; i < NELEMS(files); i++) {
		if (creat)
			touch(files[i]);
		else
			erase(files[i]);
	}

	if (creat)
		symlink("config2.cfg", STARTUP_CONFIG);
	else
		erase(STARTUP_CONFIG);

	return 0;
}
Exemplo n.º 13
0
static void
mrb_wslay_event_on_msg_recv_callback(wslay_event_context_ptr ctx,
  const struct wslay_event_on_msg_recv_arg *arg, void *user_data)
{
  mrb_wslay_user_data *data = (mrb_wslay_user_data *) user_data;
  mrb_state *mrb = data->mrb;

  int ai = mrb_gc_arena_save(mrb);
  struct mrb_jmpbuf *prev_jmp = mrb->jmp;
  struct mrb_jmpbuf c_jmp;

  MRB_TRY(&c_jmp) {
    mrb->jmp = &c_jmp;

    mrb_value argv[4];
    argv[0] = mrb_fixnum_value(arg->rsv);
    argv[1] = MRB_GET_OPCODE(mrb_fixnum_value(arg->opcode));
    argv[2] = mrb_str_new(mrb, (const char *) arg->msg, arg->msg_length);
    argv[3] = MRB_GET_STATUSCODE(mrb_fixnum_value(arg->status_code));

    mrb_value on_msg_recv_arg = mrb_obj_new(mrb,
      mrb_class_get_under(mrb,
        mrb_module_get_under(mrb,
          mrb_module_get(mrb, "Wslay"), "Event"), "OnMsgRecvArg"), NELEMS(argv), argv);

    mrb_assert(mrb_type(data->on_msg_recv_callback) == MRB_TT_PROC);
    mrb_yield(mrb, data->on_msg_recv_callback, on_msg_recv_arg);

    mrb_gc_arena_restore(mrb, ai);

    mrb->jmp = prev_jmp;
  } MRB_CATCH(&c_jmp) {
    mrb->jmp = prev_jmp;
    wslay_event_set_error(ctx, WSLAY_ERR_CALLBACK_FAILURE);
    mrb_gc_arena_restore(mrb, ai);
    MRB_THROW(mrb->jmp);
  } MRB_END_EXC(&c_jmp);
}
String Accelerometer::processor() {
  String output;
  for (int axis=0; axis<3; axis++) {
    average_delta_a[axis]  = 0;
  }
  
  for (int i=0; i<iterations; i++) {
    readAccelerometer();
    for (int axis=0; axis<3; axis++) {
      //delta_a[axis][i]=current_acceleration[axis] - previous_acceleration[axis];
      //average_delta_a[axis] += delta_a[axis][i];
      average_delta_a[axis] += current_acceleration[axis] - previous_acceleration[axis];
    }
    delay(delta);
  }

  for (int axis=0; axis<3; axis++) {
    average_delta_a[axis] = average_delta_a[axis] / iterations;
    
    if (abs(average_delta_a[axis]) > mThreshold
      && (millis() - previous_event_time[axis]) > mEventThreshold) {
      if (previous_event[axis] > 0 && average_delta_a[axis] < 0) { // turning point
        output = axes[axis][0];
      } else if (previous_event[axis] < 0 && average_delta_a[axis] > 0) { // turning point 
        output = axes[axis][1];
      }
      previous_event_time[axis] = millis(); // update last event
      previous_event[axis] = average_delta_a[axis]; // store this last acceleration value
    }
    
  }
  
  // store previous acceleration
  for (int i=0; i<NELEMS(current_acceleration); i++) {
    previous_acceleration[i] = current_acceleration[i];
  }
  return output;
}
Exemplo n.º 15
0
static error test_enumerate_ids_by_tags(State *state)
{
  error err;
  int   cont;
  char  buf[256];

  {
    static const tagdb_tag want[] = { 0, 1 };

    printf("ids tagged with '%s' and '%s'...\n",
           tagnames[want[0]], tagnames[want[1]]);

    cont = 0;
    do
    {
      err = tagdb_enumerate_ids_by_tags(state->db, want, NELEMS(want),
                                              &cont, buf, sizeof(buf));
      if (err)
        goto Failure;

      if (cont)
      {
        printf("- ");
        printdigest(buf);
        printf("\n");
      }
    }
    while (cont);
  }

  return error_OK;


Failure:

  return err;
}
Exemplo n.º 16
0
void preferences_save_media(int fd)
{
 Wire w;
 int i, n;
 char *medium_defs="MEDIUM_DEFINITIONS";

  DBG(DBG_proc, "preferences_save_media\n");

  w.io.fd = fd;
  w.io.read = read;
  w.io.write = write;
  xsane_rc_io_w_init(&w);
  xsane_rc_io_w_set_dir(&w, WIRE_ENCODE);

  xsane_rc_io_w_string(&w, &medium_defs);
  xsane_rc_io_w_word(&w, &preferences.medium_definitions);

  /* save media */

  n=0;

  DBG(DBG_info, "saving %d medium definitions\n", preferences.medium_definitions);

  while (n < preferences.medium_definitions)
  {
    DBG(DBG_info2, "=> saving medium definition %s\n", preferences.medium[n]->name);
    for (i = 0; i < NELEMS(desc_medium); ++i)
    {
      xsane_rc_io_w_string(&w, &desc_medium[i].name);
      (*desc_medium[i].codec) (&w, preferences.medium[n], desc_medium[i].offset);
    }
    n++;
  }

  xsane_rc_io_w_set_dir(&w, WIRE_DECODE);	/* flush it out */
  xsane_rc_io_w_exit(&w);
}
Exemplo n.º 17
0
static unsigned emitasm(Node p, int nt) {
	int rulenum;
	short *nts;
	char *fmt;
	Node kids[10];

	p = reuse(p, nt);
	rulenum = getrule(p, nt);
	nts = IR->x._nts[rulenum];
	fmt = IR->x._templates[rulenum];
	assert(fmt);
	if (IR->x._isinstruction[rulenum] && p->x.emitted)
		print("%s", p->syms[RX]->x.name);
	else if (*fmt == '#')
		(*IR->x.emit2)(p);
	else {
		if (*fmt == '?') {
			fmt++;
			assert(p->kids[0]);
			if (p->syms[RX] == p->x.kids[0]->syms[RX])
				while (*fmt++ != '\n')
					;
		}
		for ((*IR->x._kids)(p, rulenum, kids); *fmt; fmt++)
			if (*fmt != '%')
				(void)putchar(*fmt);
			else if (*++fmt == 'F')
				print("%d", framesize);
			else if (*fmt >= '0' && *fmt <= '9')
				emitasm(kids[*fmt - '0'], nts[*fmt - '0']);
			else if (*fmt >= 'a' && *fmt < 'a' + NELEMS(p->syms))
				fputs(p->syms[*fmt - 'a']->x.name, stdout);
			else
				(void)putchar(*fmt);
	}
	return 0;
}
Exemplo n.º 18
0
static void *
extract_db_exec_stat (FILE * fp, const char *dbname, T_CM_ERROR * err_buf)
{
  unsigned int nitem = 0;
  char linebuf[LINE_MAX];
  char prop_name[100];
  T_CM_DB_EXEC_STAT *stat;
  stat = (T_CM_DB_EXEC_STAT *) calloc (1, sizeof (*stat));
  if (stat == NULL)
    {
      cm_set_error (err_buf, CM_OUT_OF_MEMORY);
      return NULL;
    }
  while (fgets (linebuf, sizeof (linebuf), fp))
    {
      unsigned int *member_ptr;
      unsigned int prop_val;
      memset (prop_name, 0, sizeof (prop_name));
      sscanf (linebuf, "%99s%*s%u", prop_name, &prop_val);
      member_ptr = get_statdump_member_ptr (stat, prop_name);
      if (!member_ptr)
	continue;
      *member_ptr = prop_val;
      nitem++;
    }
  if (nitem < NELEMS (statdump_offset))
    {
      err_buf->err_code = CM_READ_STATDUMP_INFO_ERROR;
      snprintf (err_buf->err_msg, sizeof (err_buf->err_msg) - 1,
		ER (err_buf->err_code), dbname);
      FREE_MEM (stat);
      return NULL;
    }

  return stat;

}
Exemplo n.º 19
0
// monitor output from our process to determine which part of the build we're in
void CASW_Map_Builder::UpdateProgress()
{
	// copy the new chars into our buffer
	int newcharslen = Q_strlen(m_szProcessBuffer);
	for (int i=0;i<newcharslen;i++)
	{
		m_szOutputBuffer[m_iOutputBufferPos++] = m_szProcessBuffer[i];
		// if we go over the end of our output buffer, then shift everything back by half the buffer and continue
		if (m_iOutputBufferPos >= MAP_BUILD_OUTPUT_BUFFER_SIZE)
		{
			for (int k=0;k<MAP_BUILD_OUTPUT_BUFFER_HALF_SIZE;k++)
			{
				m_szOutputBuffer[k] = m_szOutputBuffer[k + MAP_BUILD_OUTPUT_BUFFER_HALF_SIZE];
			}
			m_iOutputBufferPos = MAP_BUILD_OUTPUT_BUFFER_HALF_SIZE;
		}
	}

	// now scan our buffer for progress messages in reverse order
	int iNumSearch = NELEMS(s_szProgressTerms);
	for (int iSearch=iNumSearch-1;iSearch>m_iCurrentBuildSearch;iSearch--)
	{
		char *pos = Q_strstr(m_szOutputBuffer, s_szProgressTerms[iSearch]);
		if ( pos )
		{
			//Msg("Output (%s) matched (%s) result %s at %d\n", m_szOutputBuffer, s_szProgressTerms[iSearch], pos, pos - m_szOutputBuffer);
			m_iCurrentBuildSearch = iSearch;
			m_flProgress = float(iSearch) / float (iNumSearch);
			if (Q_strlen(s_szStatusLabels[iSearch]) > 0)
			{
				Q_snprintf( m_szStatusMessage, sizeof(m_szStatusMessage), "%s", s_szStatusLabels[iSearch] );

			}
			break;
		}
	}
}
Exemplo n.º 20
0
char *stringn(char *str, int len)
{
    int i;
    unsigned int h;
    char *end;
    struct string *p;

    /* hash function */
    for (h = 0, i = len, end = str; i > 0; i--)
	h = (h<<1) + scatter[*(unsigned char *)end++];
    h &= NELEMS(buckets) - 1;

    for (p = buckets[h]; p; p = p->link)
	if (len == p->len) {
	    char *s1 = str, *s2 = p->str;
	    do {
		if (s1 == end)
		    return p->str;
	    } while (*s1++ == *s2++);
	}
    {
	static char *next, *strlimit;
	if (next + len + 1 >= strlimit) {
	    int n = len + 4*1024;
	    next = allocate(n, PERM);
	    strlimit = next + n;
	}
	NEW(p, PERM);
	p->len = len;
	for (p->str = next; str < end; )
	    *next++ = *str++;
	*next++ = 0;
	p->link = buckets[h];
	buckets[h] = p;
	return p->str;
    }
}
Exemplo n.º 21
0
/*
This routine dispatches the control message to the appropriate
callback routine, it outght to be called by sane_control_option
after any driver specific validation.
*/
static SANE_Status
dispatch_control_option (SANE_Handle handle, SANE_Int option,
			 SANE_Action action, void *value, SANE_Int * info)
{
  SANE_Option *op = so + option;
  SANE_Int myinfo = 0;
  SANE_Status status = SANE_STATUS_GOOD;

  if (option < 0 || option >= NELEMS (so))
    return SANE_STATUS_INVAL;	/* Unknown option ... */

  if ((action == SANE_ACTION_SET_VALUE) &&
      ((op->descriptor->cap & SANE_CAP_SOFT_SELECT) == 0))
    return SANE_STATUS_INVAL;

  if ((action == SANE_ACTION_GET_VALUE) &&
      ((op->descriptor->cap & SANE_CAP_SOFT_DETECT) == 0))
    return SANE_STATUS_INVAL;

  if ((action == SANE_ACTION_SET_AUTO) &&
      ((op->descriptor->cap & SANE_CAP_AUTOMATIC) == 0))
    return SANE_STATUS_INVAL;

  if (action == SANE_ACTION_SET_VALUE)
    {
      status = sanei_constrain_value (op->descriptor, value, &myinfo);
      if (status != SANE_STATUS_GOOD)
	return status;
    }

  status = (op->callback) (op, handle, action, value, &myinfo);

  if (info)
    *info = myinfo;

  return status;
}
Exemplo n.º 22
0
Arquivo: main.c Projeto: S010/misc
GtkWidget *
create_main_view(void) {
    int i;
    GtkWidget *vbox, *hbox;
    GtkWidget *tool_button;
    GtkWidget *scrolled_window;
    struct {
        const gchar *stock_id;
        void *click_handler;
    } tool_buttons[] = {
        { GTK_STOCK_GO_BACK,    handle_back_clicked    },
        { GTK_STOCK_GO_FORWARD, handle_forward_clicked },
        { GTK_STOCK_HOME,       handle_home_clicked    },
        { GTK_STOCK_GO_UP,      handle_up_clicked      }
    };

    vbox = gtk_vbox_new(FALSE, 0);
    hbox = gtk_hbox_new(FALSE, 0);
    path_entry = gtk_entry_new();
    icon_view = create_icon_view();
    scrolled_window = create_scrolled_window(icon_view);

    g_signal_connect(G_OBJECT(path_entry), "insert-at-cursor", G_CALLBACK(handle_path_entered), NULL);

    for (i = 0; i < NELEMS(tool_buttons); ++i) {
        tool_button = (GtkWidget *) gtk_tool_button_new_from_stock(tool_buttons[i].stock_id);
        g_signal_connect(G_OBJECT(tool_button), "clicked", G_CALLBACK(tool_buttons[i].click_handler), NULL);
        gtk_box_pack_start(GTK_BOX(hbox), tool_button, FALSE, FALSE, 0);
    }

    gtk_box_pack_start(GTK_BOX(hbox), path_entry, TRUE, TRUE, 0);
    
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);

    return vbox;
}
Exemplo n.º 23
0
static void animateacts__Gv(void)
{
  struct act **a4 = acttable;

  for (unsigned int a3 = 1; a3 < NELEMS(acttable); a3++)
  {
    struct act *act = *a4;
    a4++;

    if (act == NULL)
    {
      continue;
    }

    if (act->pad_a[0] == 0)
    {
      continue;
    }

    if (act->pad_a[1] == 0)
    {
      continue;
    }

    float f0 = act->flt_c - (act->flt_f + act->flt_g);
    f0 = act->flt_b * f0;
    if (f0 < 0)
    {
      act->flt_g = act->flt_c;
      act->pad_a[1] = 0;
    }
    else
    {
      act->flt_g = act->flt_f + act->flt_g;
    }
  }
}
Exemplo n.º 24
0
	void LoadAdminList(const std::wstring adminPath, COutStream* out)
	{
		CInFile file;
		if (!file.Open(adminPath))
			return; // may not exist

		char line[4096];
		int n = 1;
		while (file.ReadLine<char>(line, NELEMS(line), NULL)) {
			std::vector<std::string> tokens = Tokenize<std::string>(line,",");
			if (tokens.size() == 3) {
				int level = atoi(tokens[2].c_str());
				result_t result = add(tokens[1], tokens[0], level);
				if (result == E_LEVEL_NOT_EXIST && out != NULL) {
					*out << adminPath << L" : invalid access level (line "
						<< n << L")" << endl; 
				}
			} else if (out) {
				*out << adminPath << L" : line " << n << 
					L" is incorrectly formatted." << endl;
			}
			n++;
		}
	}
Exemplo n.º 25
0
int
main(void){
    int a[] = {0,1,2,3,4,5,6,7,8,9};
    int i;

    List* list = newlist();
    for(i = 0; i < NELEMS(a); i++){
        insert(list, a[i]);
    }

    Node* np;
    for(np = list->first; np; np = np->next){
        printf("%d ", np->data);
    }
    printf("\n");

    delete(list, 3);
    for(np = list->first; np; np = np->next){
        printf("%d ", np->data);
    }
    printf("\n");

    delete(list, 0);
    for(np = list->first; np; np = np->next){
        printf("%d ", np->data);
    }
    printf("\n");

    delete(list, 9);
    for(np = list->first; np; np = np->next){
        printf("%d ", np->data);
    }
    printf("\n");

    freelist(list);
}
Exemplo n.º 26
0
void InitMods(           // initialize ASM model
    vec_Mod&    mods,    // out: ASM model (only one model in this version of Stasm)
    const char* datadir) // in: directory of face detector files
{
    if (mods.empty())    // models not yet initialized?
    {
        mods.resize(1);  // 1 model

        static const Mod mod_yaw00( // constructor, see asm.h
            EYAW00,      // eyaw
            ESTART_EYES, // estart
            datadir,
            yaw00_meanshape,
            yaw00_eigvals,
            yaw00_eigvecs,
            20,  // neigs (value from empirical testing)
            1.5, // bmax  (value from empirical testing)
            SHAPEHACKS_DEFAULT | SHAPEHACKS_SHIFT_TEMPLE_OUT, // hackbits
            YAW00_DESCMODS, // defined in yaw00.mh
            NELEMS(YAW00_DESCMODS));

        mods[0] = &mod_yaw00;
    }
}
Exemplo n.º 27
0
static void
recv_stop (Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg)
{
  Call *c = (Call *) obj;
  int index;
  Time transfer_time;
  assert (et == EV_CALL_RECV_STOP && object_is_call (c));
  assert (c->basic.time_recv_start > 0);
  transfer_time=timer_now () - c->basic.time_recv_start;
  basic.call_xfer_sum += transfer_time;
 basic.hdr_bytes_received += c->reply.header_bytes;
  basic.reply_bytes_received += c->reply.content_bytes;
  basic.footer_bytes_received += c->reply.footer_bytes;

  index = (c->reply.status / 100);
  assert ((unsigned) index < NELEMS (basic.num_replies));
  ++basic.num_replies[index];
  ++num_replies;
#ifdef EXTENDED_STATS
  	basic.measurement[measure_index].connect=c->conn->basic.connect;
        basic.measurement[measure_index].reply=c->basic.reply;
  	basic.measurement[measure_index].xfer=transfer_time;
	basic.measurement[measure_index].response_size = c->reply.header_bytes + c->reply.content_bytes + c->reply.footer_bytes;
        basic.measurement[measure_index].id = c->sess_id;
	if(c->conn->basic.connect!=-1)		
		basic.measurement[measure_index].start=c->conn->basic.time_connect_start-start;
  	else		
		basic.measurement[measure_index].start=c->basic.time_send_start-start;
  	basic.measurement[measure_index].num_active_conns=num_active_conns;
  	measure_index++;
  	if(measure_index==MAX_LOG_SIZE)
		measure_index=0;
#endif
  c->conn->basic.connect=-1;
  ++c->conn->basic.num_calls_completed;
}
Exemplo n.º 28
0
int main() {
    srand(time(NULL));

    int intarr[] = { 1, -5, 7, 3, 20, 2 };

    print_type(NELEMS(intarr), printf("%d,", intarr[i]));
    shuffle(intarr, NELEMS(intarr), sizeof(intarr[0]));
    print_type(NELEMS(intarr), printf("%d,", intarr[i]));

    struct cmplex cmparr[] = {
        { 1, 3.14 },
        { 5, 7.12 },
        { 9, 8.94 },
        { 20, 1.84 }
    };

    print_type(NELEMS(intarr), printf("{%d %f},", cmparr[i].foo, cmparr[i].bar));
    shuffle(cmparr, NELEMS(cmparr), sizeof(cmparr[0]));
    print_type(NELEMS(intarr), printf("{%d %f},", cmparr[i].foo, cmparr[i].bar));

    return 0;
}
Exemplo n.º 29
0
static int build_vpbp(VirtualPBP *vpbp)
{
    int ret, i;
    u32 off;

    printk("Need to build vpbp %s\n", vpbp->name);
    memset(vpbp->header, 0, sizeof(vpbp->header));
    memset(vpbp->sects, 0, sizeof(vpbp->sects));
    vpbp->enabled = 1;
    vpbp->file_pointer = 0;
    vpbp->header[0] = 0x50425000; // PBP magic
    vpbp->header[1] = 0x10000; // version

    // fill vpbp offsets
    off = 0x28;

    ret = isoOpen(vpbp->name);

    if (ret < 0) {
        printk("%s: isoOpen -> %d\n", __func__, ret);
        ret = add_cache(vpbp);

        return ret;
    }

    for(i=0; i<NELEMS(pbp_entries); ++i) {
        vpbp->header[i+2] = off;

        if (pbp_entries[i].enabled) {
            PBPSection *sec = &vpbp->sects[i];

            ret = isoGetFileInfo(pbp_entries[i].name, &sec->size, &sec->lba);

            if (ret < 0) {
                if (i == 0) {
                    // no PARAM.SFO?
                    // then it's a bad ISO
                    isoClose();

                    return -36;
                } else {
                    continue;
                }
            }

            if (i == 0) {
                off += sizeof(virtualsfo);
            } else {
                off += sec->size;
            }
        }
    }

    vpbp->pbp_total_size = vpbp->header[9];
    get_iso_file_size(vpbp->name, &vpbp->iso_total_size);
    ret = add_cache(vpbp);
    printk("%s: add_cache -> %d\n", __func__, ret);
    isoClose();

    return ret;
}
Exemplo n.º 30
0
static int
opensl_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name,
                  cubeb_stream_params stream_params, unsigned int latency,
                  cubeb_data_callback data_callback, cubeb_state_callback state_callback,
                  void * user_ptr)
{
  cubeb_stream * stm;

  assert(ctx);

  *stream = NULL;

  if (stream_params.channels < 1 || stream_params.channels > 32 ||
      latency < 1 || latency > 2000) {
    return CUBEB_ERROR_INVALID_FORMAT;
  }

  SLDataFormat_PCM format;

  format.formatType = SL_DATAFORMAT_PCM;
  format.numChannels = stream_params.channels;
  // samplesPerSec is in milliHertz
  format.samplesPerSec = stream_params.rate * 1000;
  format.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
  format.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
  format.channelMask = stream_params.channels == 1 ?
                       SL_SPEAKER_FRONT_CENTER :
                       SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;

  switch (stream_params.format) {
  case CUBEB_SAMPLE_S16LE:
    format.endianness = SL_BYTEORDER_LITTLEENDIAN;
    break;
  case CUBEB_SAMPLE_S16BE:
    format.endianness = SL_BYTEORDER_BIGENDIAN;
    break;
  default:
    return CUBEB_ERROR_INVALID_FORMAT;
  }

  stm = calloc(1, sizeof(*stm));
  assert(stm);

  stm->context = ctx;
  stm->data_callback = data_callback;
  stm->state_callback = state_callback;
  stm->user_ptr = user_ptr;

  stm->inputrate = stream_params.rate;
  stm->latency = latency;
  stm->stream_type = stream_params.stream_type;
  stm->framesize = stream_params.channels * sizeof(int16_t);

  int r = pthread_mutex_init(&stm->mutex, NULL);
  assert(r == 0);

  SLDataLocator_BufferQueue loc_bufq;
  loc_bufq.locatorType = SL_DATALOCATOR_BUFFERQUEUE;
  loc_bufq.numBuffers = NBUFS;
  SLDataSource source;
  source.pLocator = &loc_bufq;
  source.pFormat = &format;

  SLDataLocator_OutputMix loc_outmix;
  loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX;
  loc_outmix.outputMix = ctx->outmixObj;
  SLDataSink sink;
  sink.pLocator = &loc_outmix;
  sink.pFormat = NULL;

#if defined(__ANDROID__)
  const SLInterfaceID ids[] = {ctx->SL_IID_BUFFERQUEUE,
                               ctx->SL_IID_VOLUME,
                               ctx->SL_IID_ANDROIDCONFIGURATION};
  const SLboolean req[] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
#else
  const SLInterfaceID ids[] = {ctx->SL_IID_BUFFERQUEUE, ctx->SL_IID_VOLUME};
  const SLboolean req[] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
#endif
  assert(NELEMS(ids) == NELEMS(req));
  SLresult res = (*ctx->eng)->CreateAudioPlayer(ctx->eng, &stm->playerObj,
                                                &source, &sink, NELEMS(ids), ids, req);

  uint32_t preferred_sampling_rate = stm->inputrate;
  // Sample rate not supported? Try again with primary sample rate!
  if (res == SL_RESULT_CONTENT_UNSUPPORTED) {
    if (opensl_get_preferred_sample_rate(ctx, &preferred_sampling_rate)) {
      opensl_stream_destroy(stm);
      return CUBEB_ERROR;
    }

    format.samplesPerSec = preferred_sampling_rate * 1000;
    res = (*ctx->eng)->CreateAudioPlayer(ctx->eng, &stm->playerObj,
                                         &source, &sink, NELEMS(ids), ids, req);
  }

  if (res != SL_RESULT_SUCCESS) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  stm->outputrate = preferred_sampling_rate;
  stm->bytespersec = preferred_sampling_rate * stm->framesize;
  stm->queuebuf_len = (stm->bytespersec * latency) / (1000 * NBUFS);
  // round up to the next multiple of stm->framesize, if needed.
  if (stm->queuebuf_len % stm->framesize) {
    stm->queuebuf_len += stm->framesize - (stm->queuebuf_len % stm->framesize);
  }

  stm->resampler = cubeb_resampler_create(stm, stream_params,
                                          preferred_sampling_rate,
                                          data_callback,
                                          stm->queuebuf_len / stm->framesize,
                                          user_ptr,
                                          CUBEB_RESAMPLER_QUALITY_DEFAULT);

  if (!stm->resampler) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  int i;
  for (i = 0; i < NBUFS; i++) {
    stm->queuebuf[i] = malloc(stm->queuebuf_len);
    assert(stm->queuebuf[i]);
  }

#if defined(__ANDROID__)
  SLuint32 stream_type = convert_stream_type_to_sl_stream(stream_params.stream_type);
  if (stream_type != 0xFFFFFFFF) {
    SLAndroidConfigurationItf playerConfig;
    res = (*stm->playerObj)->GetInterface(stm->playerObj,
          ctx->SL_IID_ANDROIDCONFIGURATION, &playerConfig);
    res = (*playerConfig)->SetConfiguration(playerConfig,
          SL_ANDROID_KEY_STREAM_TYPE, &stream_type, sizeof(SLint32));
    if (res != SL_RESULT_SUCCESS) {
      opensl_stream_destroy(stm);
      return CUBEB_ERROR;
    }
  }
#endif

  res = (*stm->playerObj)->Realize(stm->playerObj, SL_BOOLEAN_FALSE);
  if (res != SL_RESULT_SUCCESS) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  res = (*stm->playerObj)->GetInterface(stm->playerObj, ctx->SL_IID_PLAY, &stm->play);
  if (res != SL_RESULT_SUCCESS) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  res = (*stm->playerObj)->GetInterface(stm->playerObj, ctx->SL_IID_BUFFERQUEUE,
                                    &stm->bufq);
  if (res != SL_RESULT_SUCCESS) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  res = (*stm->playerObj)->GetInterface(stm->playerObj, ctx->SL_IID_VOLUME,
                                        &stm->volume);

  if (res != SL_RESULT_SUCCESS) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  res = (*stm->play)->RegisterCallback(stm->play, play_callback, stm);
  if (res != SL_RESULT_SUCCESS) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  res = (*stm->play)->SetCallbackEventsMask(stm->play, (SLuint32)SL_PLAYEVENT_HEADATMARKER);
  if (res != SL_RESULT_SUCCESS) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  res = (*stm->bufq)->RegisterCallback(stm->bufq, bufferqueue_callback, stm);
  if (res != SL_RESULT_SUCCESS) {
    opensl_stream_destroy(stm);
    return CUBEB_ERROR;
  }

  *stream = stm;
  return CUBEB_OK;
}