Beispiel #1
0
void BlabbleCall::OnCallState(pjsua_call_id call_id, pjsip_event *e)
{
	pjsua_call_info info;
	if (pjsua_call_get_info(call_id, &info) == PJ_SUCCESS)
	{
		if (info.state == PJSIP_INV_STATE_DISCONNECTED) 
		{
			RemoteEnd(info);
		}
		else if (info.state == PJSIP_INV_STATE_CALLING)
		{
			if (on_call_ringing_)
				on_call_ringing_->InvokeAsync("", FB::variant_list_of(BlabbleCallWeakPtr(get_shared())));

			BlabbleAccountPtr p = parent_.lock();
			if (p)
				p->OnCallRingChange(get_shared(), info);
		}
		else if (info.state == PJSIP_INV_STATE_CONFIRMED)
		{
			if (on_call_connected_)
				on_call_connected_->InvokeAsync("", FB::variant_list_of(BlabbleCallWeakPtr(get_shared())));

			BlabbleAccountPtr p = parent_.lock();
			if (p)
				p->OnCallRingChange(get_shared(), info);
		}
	}
}
Beispiel #2
0
//Ended by us
void BlabbleCall::LocalEnd()
{
	pjsua_call_id old_id = INTERLOCKED_EXCHANGE((volatile long *)&call_id_, (long)INVALID_CALL);
	if (old_id == INVALID_CALL || 
		old_id < 0 || old_id >= (long)pjsua_call_get_max_count())
	{
		return;
	}

	StopRinging();

	pjsua_call_info info;
	if (pjsua_call_get_info(old_id, &info) == PJ_SUCCESS &&
		info.conf_slot > 0) 
	{
		//Kill the audio
		pjsua_conf_disconnect(info.conf_slot, 0);
		pjsua_conf_disconnect(0, info.conf_slot);
	}

	pjsua_call_hangup(old_id, 0, NULL, NULL);
	
	if (on_call_end_)
	{
		BlabbleCallPtr call = get_shared();
		on_call_end_->getHost()->ScheduleOnMainThread(call, boost::bind(&BlabbleCall::CallOnCallEnd, call));
	}

	BlabbleAccountPtr p = parent_.lock();
	if (p)
		p->OnCallEnd(get_shared());
}
Beispiel #3
0
//Ended by remote, could be becuase of an error
void BlabbleCall::RemoteEnd(const pjsua_call_info &info)
{
	pjsua_call_id old_id = INTERLOCKED_EXCHANGE((volatile long *)&call_id_, (long)INVALID_CALL);
	if (old_id == INVALID_CALL || 
		old_id < 0 || old_id >= (long)pjsua_call_get_max_count())
	{
		return;
	}

	StopRinging();

	//Kill the audio
	if (info.conf_slot > 0) 
	{
		pjsua_conf_disconnect(info.conf_slot, 0);
		pjsua_conf_disconnect(0, info.conf_slot);
	}

	pjsua_call_hangup(old_id, 0, NULL, NULL);

	if (info.last_status > 400)
	{
		std::string callerId;
		if (info.remote_contact.ptr == NULL)
		{
			callerId =std::string(info.remote_info.ptr, info.remote_info.slen);
		} 
		else
		{
			callerId = std::string(info.remote_contact.ptr, info.remote_contact.slen);
		}

		if (on_call_end_)
		{
			BlabbleCallPtr call = get_shared();
			on_call_end_->getHost()->ScheduleOnMainThread(call, boost::bind(&BlabbleCall::CallOnCallEnd, call, info.last_status));
		}
	} else {
		if (on_call_end_)
		{
			BlabbleCallPtr call = get_shared();
			on_call_end_->getHost()->ScheduleOnMainThread(call, boost::bind(&BlabbleCall::CallOnCallEnd, call));
		}
	}

	BlabbleAccountPtr p = parent_.lock();
	if (p)
		p->OnCallEnd(get_shared());
}
Beispiel #4
0
/*
 * file_seg:  <path-name> [<offset>[kmgp] <length>[kmgp]  [private|shared]]
 */
static int file_seg(char *args)
{
	glctx_t *gcp = &glctx;

	char *pathname, *nextarg;
	range_t range = { 0L, 0L };
	int segflag = MAP_PRIVATE;

	args += strspn(args, whitespace);

	if (!required_arg(args, "<path-name>"))
		return CMD_ERROR;
	pathname = strtok_r(args, whitespace, &nextarg);
	args = nextarg + strspn(nextarg, whitespace);

	/*
	 * offset, length are optional
	 */
	if (get_range(args, &range, &nextarg) == CMD_ERROR)
		return CMD_ERROR;
	args = nextarg;

	if (*args != '\0') {
		segflag = get_shared(args);
		if (segflag == -1)
			return CMD_ERROR;
	}

	if (!segment_register(SEGT_FILE, pathname, &range, segflag))
		return CMD_ERROR;

	return CMD_SUCCESS;
}
Beispiel #5
0
/*
 * anon_seg:  <seg-name> <size>[kmgp] [private|shared]
 */
static int anon_seg(char *args)
{
	glctx_t *gcp = &glctx;

	char *segname, *nextarg;
	range_t range = { 0L, 0L };
	int segflag = 0;

	args += strspn(args, whitespace);

	if (!required_arg(args, "<seg-name>"))
		return CMD_ERROR;
	segname = strtok_r(args, whitespace, &nextarg);
	args = nextarg + strspn(nextarg, whitespace);

	if (!required_arg(args, "<size>"))
		return CMD_ERROR;
	args = strtok_r(args, whitespace, &nextarg);
	range.length = get_scaled_value(args, "size");
	if (range.length == BOGUS_SIZE)
		return CMD_ERROR;
	args = nextarg + strspn(nextarg, whitespace);

	if (*args != '\0') {
		segflag = get_shared(args);
		if (segflag == -1)
			return CMD_ERROR;
	}

	if (!segment_register(SEGT_ANON, segname, &range, segflag))
		return CMD_ERROR;

	return CMD_SUCCESS;
}
Beispiel #6
0
/* Return an identifier for an shared memory segment of at least size
   SIZE which is associated with KEY.  */
int
__shmget (key_t key, size_t size, int shmflags)
{
  error_t err;
  int fd;

  if (key == IPC_PRIVATE || shmflags & IPC_EXCL)
    /* An exclusive shared memory segment must be created.  */
    err = get_exclusive (shmflags, size, &key, &fd);
  else
    err = get_shared (shmflags, size, key, &fd);

  if (err)
    {
      errno = err;
      return -1;
    }

  /* From here, we can't fail.  That's important, as otherwise we
     would need to unlink the file if we created it (in that case, the
     code above would have to be changed to pass a "created" flag down
     to the caller).  */

  __close (fd);

  return key;
}
Beispiel #7
0
static int choose_shader(int sel) {
    // This part is a little tricky because I want the fileselector when I
    // select this, but I don't want the whole path to be displayed, just
    // the filename selected alone. Tricky, but not long... !
    /* Something prevents glsl shaders from working. Tried to convert them from
     * cg shaders, got an error about "must write to gl_Position" when linking.
     * So they are disabled for now */
    char *exts[] = { "*.shader","*.glsl", NULL };
    char *dir,old[FILENAME_MAX];
    dir = get_shared("shaders");
    strcpy(old,ogl.shader);
    if (!strcmp(ogl.shader,"None"))
	*ogl.shader = 0;
    else {
	strcpy(dir,ogl.shader);
	char *p = strrchr(dir,SLASH[0]);
	if (p) *p = 0;
    }
    fsel(dir,exts,ogl.shader,"Select shader");
    if (ogl.shader[strlen(ogl.shader)-1] == SLASH[0] &&
	    strcmp(old,"None")) { // cancelled ?
	if (MessageBox(_("Confirmation"),_("Disable shaders ?"),_("Yes|No")) == 1)
	    strcpy(ogl.shader,"None");
	else
	    strcpy(ogl.shader,old);
    } else {
	ogl.render = 1;
    }
    preinit_ogl_options();
    return 0;
}
Beispiel #8
0
static
int little_lock(sqlite3_file *file, int lock) {
  int res;
  little_file *self = (little_file*)file;

  trace("LOCK UP %s...\n", locktypeName(lock));
  fflush(stdout);
  switch (lock) {
    case SQLITE_LOCK_SHARED:
      res = get_shared(self->name);
      if (res < 0) trace ("Optimistic locking! forge ahead\n");
      else self->shared_lock_number = res;

      // don't worry if we don't get the lock, we have versioning
      res = get_version(self->name, &(self->version), &(self->nextfreeblock));
      if (errno == ENOENT) res = 0;
      break;

    case SQLITE_LOCK_RESERVED:
      res = get_reserved(self->name);
      break;

    case SQLITE_LOCK_EXCLUSIVE:
      res = get_exclusive(self->name, self->shared_lock_number);
      self->shared_lock_number = -1;
      ++(self->version);
      break;

    default: return SQLITE_ERROR;
  }
  if (res == -EAGAIN) return SQLITE_BUSY;
  if (res < 0) return SQLITE_ERROR;
  trace("LOCK UP %s OK\n", locktypeName(lock));
  return SQLITE_OK;
}
Beispiel #9
0
void TFont::select_ideal_font(int ideal_width, int ideal_height) {
  unsigned int bestw = 0, besth=0;
  char *fdir = get_shared("fonts");
  DIR *dir = opendir(fdir);
  loaded_font = NULL;
  if (dir) {
    char selected[256];
    unsigned int w,h;
    struct dirent *entry;
    // 1st look for height
    while ((entry = readdir(dir))) {
      get_font_dimensions(entry->d_name,&w,&h);
      if (abs(h-ideal_height) < abs(besth - ideal_height))
	besth = h;
    }
    rewinddir(dir);
    // Now look for the best width with this height
    while ((entry = readdir(dir))) {
      get_font_dimensions(entry->d_name,&w,&h);
      if (h == besth && (abs(w-ideal_width) < abs(bestw-ideal_width))) {
	strcpy(selected, entry->d_name);
	bestw = w;
      }
    }
    closedir(dir);
    TFont::load_font(selected);
  }
}
Beispiel #10
0
int do_about(int sel) {
    char *path;
#ifdef __GNUC__
    {
	int major = __GNUC__;
	int minor = __GNUC_MINOR__;
#ifdef __GNUC_PATCHLEVEL__
	int patchlevel = __GNUC_PATCHLEVEL__;
#else
	int patchlevel = 0;
#endif
#ifdef __clang__
	major = __clang_major__;
	minor = __clang_minor__;
	patchlevel = __clang_patchlevel__;
	sprintf(gcc_version,"with llvm/clang %d.%d.%d",major,minor,patchlevel);
#else
	sprintf(gcc_version,"with gcc %d.%d.%d",major,minor,patchlevel);
#endif
    }
#else
    sprintf(gcc_version,"with an unknown gcc ???");
#endif
    about_items[2].label = gcc_version;
    path = get_shared("bitmaps/raine_logo.png");
    sprintf(about_cpu, "CPU: %s", raine_cpu_model);
    about_items[3].label = about_cpu;
    char about_sdl[80];
#if HAS_NEO
    char about_sound[80];
#endif
    const SDL_version *version = SDL_Linked_Version();
    const SDL_version *img = IMG_Linked_Version();
    const SDL_version *ttf = TTF_Linked_Version();
    sprintf(about_sdl,"Linked with SDL-%d.%d.%d, SDL_image-%d.%d.%d, SDL_ttf-%d.%d.%d",version->major,version->minor,version->patch,
	    img->major,img->minor,img->patch,
	    ttf->major,ttf->minor,ttf->patch);
    about_items[4].label = about_sdl;
#if HAS_NEO
    Sound_Version sound;
    Sound_GetLinkedVersion(&sound);
    sprintf(about_sound,"SDL_sound-%d.%d.%d",
	    sound.major,sound.minor,sound.patch);

    about_items[5].label = about_sound;
#endif
#ifdef RDTSC_PROFILE
  if (cycles_per_second) {
    sprintf(about_cpu,"CPU: %s at %d MHz",raine_cpu_model,cycles_per_second/1000000);
  }
#endif
  about_menu = new TAbout_menu(_("About..."),about_items, path);
  about_menu->execute();
  delete about_menu;
  about_menu = NULL;
  return 0;
}
Beispiel #11
0
void TFont::load_font(char *myfont) {
  FILE *f;
  unsigned int len,width,height;
  get_font_dimensions(myfont,&width,&height);
  if (!width || !height) { // load default font
    charWidth = charHeight = 0;
    if (loaded_font) {
      free(loaded_font);
      loaded_font = NULL;
    }
    return;
  }
  if (strchr(myfont,'/') == 0) {
    char tpath[1024];
    sprintf(tpath,"fonts/%s",myfont);
    f = fopen(get_shared(tpath),"rb");
  } else
    f = fopen(get_shared(myfont),"rb");

  if (f) {
    fseek(f,0L,SEEK_END);
    len = ftell(f);
    fseek(f,0L,SEEK_SET);
    if (loaded_font)
      free(loaded_font);

    loaded_font = (char*)malloc(len);
    if (loaded_font) {
      fread(loaded_font,len,1,f);
      charWidth = width;
      charHeight = height;
      gfxPrimitivesSetFont(loaded_font,charWidth,charHeight);
    } else {
      charWidth = charHeight = 0;
      // in this case CharWidth = CharHeight = 8, see get_font_height...
    }
    fclose(f);
  }
}
Beispiel #12
0
bool BlabbleCall::OnCallTransferStatus(int status)
{
	if (call_id_ != INVALID_CALL) 
	{
		if (on_transfer_status_)
		{
			BlabbleCallPtr call = get_shared();
			on_transfer_status_->getHost()->ScheduleOnMainThread(call, boost::bind(&BlabbleCall::CallOnTransferStatus, call, status));
		}
	}

	return false;
}
Beispiel #13
0
void TFont_ttf::load_font(char *myfont) {
  if (!strstr(myfont,"ttf"))
    myfont = "Vera.ttf";
  char tpath[1024];
  sprintf(tpath,"fonts/%s",myfont);
  ttf = TTF_OpenFont(get_shared(tpath),charHeight*3/2);
  if ( ttf == NULL ) {
    fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",
	charHeight, myfont, SDL_GetError());
    // falling back to bitmap font
    select_ideal_font(charWidth,charHeight);
  } else {
    TTF_SetFontStyle(ttf, TTF_STYLE_NORMAL);
    dimensions("ABCDEF",&charWidth,&charHeight);
    charWidth /= 6;
  }
}
Beispiel #14
0
/*
 * map <seg-name> [<offset>[k|m|g|p] <length>[k|m|g|p]] [<seg-share>]
 */
static int map_seg(char *args)
{
	glctx_t *gcp = &glctx;

	char *segname, *nextarg;
	range_t range = { 0L, 0L };
	range_t *rangep = NULL;
	int segflag = MAP_PRIVATE;

	args += strspn(args, whitespace);
	if (!required_arg(args, "<seg-name>"))
		return CMD_ERROR;
	segname = strtok_r(args, whitespace, &nextarg);
	args = nextarg + strspn(nextarg, whitespace);

	/*
	 * offset, length are optional
	 */
	if (get_range(args, &range, &nextarg) == CMD_ERROR)
		return CMD_ERROR;
	if (args != nextarg) {
		rangep = &range;	/* override any registered range */
		args = nextarg;
	}

	if (*args != '\0') {
		segflag = get_shared(args);
		if (segflag == -1)
			return CMD_ERROR;
	}

	if (!segment_map(segname, rangep, segflag))
		return CMD_ERROR;

	return CMD_SUCCESS;
}
Beispiel #15
0
void BlabbleCall::CallOnTransferStatus(int status)
{
	on_transfer_status_->Invoke("", FB::variant_list_of(BlabbleCallWeakPtr(get_shared()))(status));
}
Beispiel #16
0
static int about_game(int sel) {
  int nb_lines = 10;
  menu = (menu_item_t *)malloc(sizeof(menu_item_t)*nb_lines);
  int used = 0;
  char *buff;
  if (do_command)
      buff = commands_buff[sel];
  else
      buff = history;

  if (buff) {
    char *s = buff;
    char *nl;
    char previous;
    TFont_ttf *font = new TFont_ttf(min_font_size);
    while ((nl = strchr(s,'\n'))) {
      char *q;
      previous = *nl;
      *nl = 0;
      if ((q=strstr(s,"<a href="))) {
	  /* Basic parsing for urls. We assume everything is lowercase with
	   * only 1 space and not more, and everything on 1 line of text.
	   * I don't was a general html parser here, just something to parse
	   * basic urls */
	  q+=8;
	  char *end;
	  char old;
	  if (*q == '"') {
	      q++;
	      end = strchr(q,'"');
	  } else
	      end = strchr(q,' ');
	  if (end) {
	      old = *end;
	      *end = 0;
	      menu[used].values_list_label[0] = strdup(q);
	      *end = old;
	      q = end+1;
	  } else
	      menu[used].values_list_label[0] = NULL;
	  q = strchr(q,'>');
	  if (q) {
	      q++;
	      end = strstr(q,"</a>");
	      if (end) {
		  old = *end;
		  *end = 0;
		  menu[used].label = strdup(q);
		  *end = old;
		  menu[used].menu_func = &menu_goto_url;
		  goto end_loop;
	      }
	  }
      }
      int w,h;
      font->dimensions(s,&w,&h);
      if (w > sdl_screen->w-50) {
	char start;
	if (s > buff) {
	  start = s[-1];
	  s[-1] = 0;
	}
	char *old = NULL;
	char *sp;
	do {
	    sp = strrchr(s,' ');
	    if (sp) {
		*sp = 0;
		if (old) *old = ' ';
		old = sp;
	    } else
		break;
	    font->dimensions(s,&w,&h);
	} while (w > sdl_screen->w-50);

	int maxlen = strlen(s);
	if (old)
	    *old = ' ';
	if (s>buff) {
	  s[-1] = start;
	}
	if (!sp)
	  sp = old;
	*nl = previous;
	if (sp && sp <= s+maxlen)
	  nl = sp;
	else
	  nl = s+maxlen;

	previous = *nl;
	*nl = 0;
      }
      while ((q = strchr(s,0x92)))
	*q = 0x27; // fix the stupid non standard ' code from krosoft

      menu[used].label = strdup(s);
      menu[used].menu_func = NULL;
      menu[used].values_list_label[0] = NULL;
end_loop:
      menu[used].value_int = NULL;
      used++;
      if (used == nb_lines) {
	nb_lines += 10;
	menu = (menu_item_t *)realloc(menu,sizeof(menu_item_t)*nb_lines);
      }
      *nl = previous;
      if (previous == ' ' || previous == '\n')
	s = nl+1;
      else
	s = nl;
    }
    delete font;
  } else {
      char *hist = get_shared("history.dat");
      if (!strcmp(hist,"history.dat")) { // No path info added -> no file !
	  int ret = MessageBox(_("Warning"),_("history.dat not found\nDownload it from http://www.arcade-history.com/index.php?page=download\nand install it in your raine directory\n"
		  "in linux ~/.raine or /usr/share/games/raine\n")
		  ,_("Open this page now !|Later maybe..."));
	  if (ret == 1)
	      goto_url("http://www.arcade-history.com/index.php?page=download");
      }
  }

  if (used) {
    menu[used].label = NULL;

    TMenu *about_menu;
    if (!do_command)
	about_menu = new TMenu(_("About this game"),menu, NULL,-1, -1,-1,-1, /* to_translate */ 0);
    else
	about_menu = new TMoves_menu((char*)menu_commands[sel].label,menu);
    about_menu->execute();
    delete about_menu;

    for (int n=0; n<used; n++) {
      free((void*)menu[n].label);
      if (menu[n].values_list_label[0])
	  free(menu[n].values_list_label[0]);
    }
  }
  free(menu);

  return 0;
}
Beispiel #17
0
void BlabbleCall::CallOnCallEnd(pjsip_status_code status)
{
	on_call_end_->Invoke("", FB::variant_list_of(BlabbleCallWeakPtr(get_shared()))(status));
}
Beispiel #18
0
void BlabbleCall::CallOnCallEnd()
{
	on_call_end_->Invoke("", FB::variant_list_of(BlabbleCallWeakPtr(get_shared())));
}