void DisplayChannel::create_primary_surface(int width, int height, uint32_t format)
{
   Canvas *canvas;
   _mark = false;
    attach_to_screen(get_client().get_application(), get_id());
    clear_area();

    AutoRef<CreatePrimarySurfaceEvent> event(new CreatePrimarySurfaceEvent(*this, width, height,
                                                                           format));
    get_client().push_event(*event);
    (*event)->wait();
    if (!(*event)->success()) {
        THROW("Create primary surface failed");
    }

    _x_res = width;
    _y_res = height;
    _format = format;

    canvas = surfaces_mngr.get_canvas(0);

#ifdef USE_OGL
    if (canvas->get_pixmap_type() == CANVAS_TYPE_GL) {
        ((GCanvas *)(canvas))->touch_context();
        screen()->set_update_interrupt_trigger(&_interrupt_update);
        screen()->set_type_gl();
    }
#endif
}
void DisplayChannel::on_disconnect()
{
    if (surfaces_mngr.is_present_canvas(0)) {
        Canvas *canvas;

        canvas = surfaces_mngr.get_canvas(0);
        canvas->clear();
    }

    if (screen()) {
        screen()->set_update_interrupt_trigger(NULL);
    }

    AutoRef<DetachChannelsEvent> detach_channels(new DetachChannelsEvent(*this));
    get_client().push_event(*detach_channels);
    if (screen()) {
        AutoRef<UnlockScreenEvent> unlock_event(new UnlockScreenEvent(screen()));
        get_client().push_event(*unlock_event);
        detach_from_screen(get_client().get_application());
    }
    get_client().deactivate_interval_timer(*_streams_timer);
    AutoRef<SyncEvent> sync_event(new SyncEvent());
    get_client().push_event(*sync_event);
    (*sync_event)->wait();
}
示例#3
0
/** Deliver mouse move events to the proper client 
 \todo Implement mouse dragging somewhere in the mouse_move chain 
 \todo Support more than one client here */
void sdl_master::mouse_move(SDL_MouseMotionEvent *old, SDL_MouseMotionEvent *fresh)
{
	if (clients[0] != 0)
	{
		if ((old->state == SDL_PRESSED) && (fresh->state == SDL_PRESSED))
		{
			//drag event generated here
			dragging = true;
		}
		else
		{
			int old_num = get_client(old->x, old->y);
			if (old_num != get_client(fresh->x, fresh->y))
			{	//pointer tried to move from one client to another
				if (clients[old_num]->mouse_leave())
				{
					printf("Prevent client %d from losing the mouse\n", old_num);
					*fresh = *old;
				}
			}
			int new_num = get_client(fresh->x, fresh->y);
			//don't do an else here, the fresh mouse position may have changed
			if (old_num == get_client(fresh->x, fresh->y))
			{	//mouse moved within a single client
				clients[old_num]->mouse_move(old, fresh);
			}
			else
			{	//mouse was allowed to leave the old client
				clients[old_num]->mouse_from(old);
				clients[new_num]->mouse_to(fresh);
			}
		}
	}
}
void DisplayChannel::streams_time()
{
    _next_timer_time = 0;
    Lock lock(_streams_lock);
    uint32_t mm_time = get_client().get_mm_time();
    uint32_t next_time = 0;
    VideoStream* stream = _active_streams;
    while (stream) {
        uint32_t next_frame_time;
        if ((next_frame_time = stream->handle_timer_update(mm_time))) {
            if (!next_time || int(next_frame_time - next_time) < 0) {
                next_time = next_frame_time;
            }
        }
        stream = stream->next;
    }
    Lock timer_lock(_timer_lock);
    mm_time = get_client().get_mm_time();
    next_time = mm_time + 15;
    if (next_time && (!_next_timer_time || int(next_time - _next_timer_time) < 0)) {
        get_client().activate_interval_timer(*_streams_timer, MAX(int(next_time - mm_time), 0));
        _next_timer_time = next_time;
    } else if (!_next_timer_time) {
        get_client().deactivate_interval_timer(*_streams_timer);
    }
    timer_lock.unlock();
    lock.unlock();
    Platform::yield();
}
示例#5
0
void
HTTP_Client_Connection::on_socket_timeout(int pending_operation, long timeout)
{
	//ACE_OS::printf("socket timeout! op_code=%d timeout=%d\n", pending_operation, timeout); //@
	//ACE_OS::printf("T");
	if ( pending_operation == CONNECT )
		++get_client().n_ct;
	else
		++get_client().n_st;
}
void DisplayChannel::reset_screen()
{
    AutoRef<UnlockScreenEvent> unlock_event(new UnlockScreenEvent(screen()));
    get_client().push_event(*unlock_event);

    screen()->set_update_interrupt_trigger(NULL);
    AutoRef<ResetTimer> reset_timer(new ResetTimer(screen()->ref(), get_client()));

    detach_from_screen(get_client().get_application());
    
    get_client().activate_interval_timer(*reset_timer, RESET_TIMEOUT);
}
void DisplayChannel::on_connect()
{
    Message* message = new Message(SPICE_MSGC_DISPLAY_INIT);
    SpiceMsgcDisplayInit init;
    init.pixmap_cache_id = 1;
    init.pixmap_cache_size = get_client().get_pixmap_cache_size();
    init.glz_dictionary_id = 1;
    init.glz_dictionary_window_size = get_client().get_glz_window_size();
    _marshallers->msgc_display_init(message->marshaller(), &init);
    post_message(message);
    AutoRef<AttachChannelsEvent> attach_channels(new AttachChannelsEvent(*this));
    get_client().push_event(*attach_channels);
}
示例#8
0
文件: funcserver.c 项目: khalilH/PC2R
/* notification de déconnexion d'un joueur */
void sorti(char *name){
  char buffer[MAX_SIZE];
  sprintf(buffer, "DECONNEXION/%s/\n", name);
  client_list *l;
  client_list *l2;
  
  /* Récupération du client à supprimer */
  client_list *tmp = get_client(clients, name);
  if(tmp == NULL){
    tmp = get_client(file_attente, name);
  }
  if(tmp == NULL){
    fprintf(stderr, "sorti : utilisateur inconnu\n");
    return;
  }
    
  /* Notification pour les utilisateurs dans la liste des joueurs */
  pthread_mutex_lock(&mutex_clients);
  l = clients;
  while(l != NULL){
    if(strcmp(l->name, name) != 0){
      write(l->socket, buffer, strlen(buffer));
    }
    l = l->next;
  }
  pthread_mutex_unlock(&mutex_clients);

  /* Notification pour les utilisateurs dans la file d'attente */
  pthread_mutex_lock(&mutex_attente);
  l2 = file_attente;
  while(l2 != NULL){
    memset(buffer, '\0', MAX_SIZE);
    if(strcmp(l2->name, name) != 0){
      write(l2->socket, buffer, strlen(buffer));
    }
    l2 = l2->next;
  }
  pthread_mutex_unlock(&mutex_attente);

  /* suppression du client des listes et annulation des threads associées */
  close(tmp->socket);
  
  pthread_mutex_lock(&mutex_clients);
  clients = suppr_client(clients, name);
  pthread_mutex_unlock(&mutex_clients);
  pthread_mutex_lock(&mutex_attente);
  file_attente = suppr_client(file_attente, name);
  pthread_mutex_unlock(&mutex_attente);
}
示例#9
0
ResultCode Store::connection_test()
{
  ResultCode rc = OK;

  // Check that we can connect to cassandra by getting a client. This logs in
  // and switches to the specified keyspace, so is a good test of whether
  // cassandra is working properly.
  TRC_STATUS("Starting store");
  try
  {
    get_client();
    release_client();
  }
  catch(TTransportException te)
  {
    TRC_ERROR("Store caught TTransportException: %s", te.what());
    rc = CONNECTION_ERROR;
  }
  catch(NotFoundException nfe)
  {
    TRC_ERROR("Store caught NotFoundException: %s", nfe.what());
    rc = NOT_FOUND;
  }
  catch(...)
  {
    TRC_ERROR("Store caught unknown exception!");
    rc = UNKNOWN_ERROR;
  }

  return rc;
}
示例#10
0
文件: funcserver.c 项目: khalilH/PC2R
/* validation de la connexion d'un utilisateur */
void bienvenue(char *name, int sock_com){
  char buffer[MAX_SIZE];
  client_list *tmp;

  pthread_mutex_lock(&mutex_clients);
  if(client_exists(clients, name)){
    /* si le nom du joueur est déjà pris */
    sprintf(buffer, "%s already used\n", name);
    write(sock_com, buffer, strlen(buffer));
    pthread_mutex_unlock(&mutex_clients);
  }else{
    /* ajout dans la file d'attente tant que le client n'est pas nommé */
    pthread_mutex_lock(&mutex_attente);
    file_attente = add_name_client(file_attente, sock_com, name);
    if(get_phase() == -1){
      /* transfert du client dans la file d'attente vers la liste des clients */
      tmp = get_client(file_attente, name);
      file_attente = suppr_client(file_attente, name);
      tmp->next = clients;
      clients = tmp;
    }
    sprintf(buffer, "BIENVENUE/%s/\n", name);
    write(sock_com, buffer, strlen(buffer));
    pthread_mutex_unlock(&mutex_clients);
    pthread_mutex_unlock(&mutex_attente);
    /* Notification à tous les clients de la connexion de ce joueur */
    connecte(name);
  }
  pthread_mutex_unlock(&mutex_clients);
}
示例#11
0
gboolean
gs_plugin_add_installed (GsPlugin *plugin,
			 GsAppList *list,
			 GCancellable *cancellable,
			 GError **error)
{
	g_autoptr(SnapdClient) client = NULL;
	g_autoptr(GPtrArray) snaps = NULL;
	guint i;

	client = get_client (plugin, error);
	if (client == NULL)
		return FALSE;

	snaps = snapd_client_get_snaps_sync (client, SNAPD_GET_SNAPS_FLAGS_NONE, NULL, cancellable, error);
	if (snaps == NULL) {
		snapd_error_convert (error);
		return FALSE;
	}

	for (i = 0; i < snaps->len; i++) {
		SnapdSnap *snap = g_ptr_array_index (snaps, i);
		g_autoptr(GsApp) app = NULL;

		app = snap_to_app (plugin, snap);
		gs_app_list_add (list, app);
	}

	return TRUE;
}
示例#12
0
gboolean
gs_plugin_app_remove (GsPlugin *plugin,
		      GsApp *app,
		      GCancellable *cancellable,
		      GError **error)
{
	g_autoptr(SnapdClient) client = NULL;

	/* We can only remove apps we know of */
	if (g_strcmp0 (gs_app_get_management_plugin (app), "snap") != 0)
		return TRUE;

	client = get_client (plugin, error);
	if (client == NULL)
		return FALSE;

	gs_app_set_state (app, AS_APP_STATE_REMOVING);
	if (!snapd_client_remove_sync (client, gs_app_get_metadata_item (app, "snap::name"), progress_cb, app, cancellable, error)) {
		gs_app_set_state_recover (app);
		snapd_error_convert (error);
		return FALSE;
	}
	gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
	return TRUE;
}
示例#13
0
 /**
  *  设置回调
  */
  void set_callback()
  {
    if (m_recv_callbackfun != NULL)
    {
      get_client()->set_callback(m_recv_callbackfun);
    }
  }
示例#14
0
int
message_complete_cb (http_parser *p)
{
  client_t *client = get_client(p);
  client->complete = 1;
  return 0;
}
示例#15
0
文件: bank.c 项目: scmilburn/ATM
Node *get_client(Node *head, char *nom){
    if(head == NULL)
        return NULL;
    if(strcmp(head->name, nom) == 0)
        return head;
    return get_client(head->next, nom);
}
void DisplayChannel::destroy_primary_surface()
{
    if (screen()) {
#ifdef USE_OGL
        if (surfaces_mngr.is_present_canvas(0)) {
            Canvas *canvas;

            canvas = surfaces_mngr.get_canvas(0);
            if (canvas->get_pixmap_type() == CANVAS_TYPE_GL) {
                screen()->unset_type_gl();
                screen()->untouch_context();
            }
        }
#endif

        reset_screen();
    }

    AutoRef<DestroyPrimarySurfaceEvent> event(new DestroyPrimarySurfaceEvent(*this));
    get_client().push_event(*event);
    (*event)->wait();
    if (!(*event)->success()) {
        THROW("Destroying primary surface failed");
    }
}
void DisplayChannel::handle_stream_create(RedPeer::InMessage* message)
{
    SpiceMsgDisplayStreamCreate* stream_create = (SpiceMsgDisplayStreamCreate*)message->data();
    int surface_id = stream_create->surface_id;

    Lock lock(_streams_lock);
    if (_streams.size() <= stream_create->id) {
        _streams.resize(stream_create->id + 1);
    }

    if (_streams[stream_create->id]) {
        THROW("stream exist");
    }

    uint32_t num_clip_rects;
    SpiceRect* clip_rects;
    set_clip_rects(stream_create->clip, num_clip_rects, clip_rects);
    _streams[stream_create->id] = new VideoStream(get_client(), *surfaces_mngr.get_canvas(surface_id),
                                                  *this, stream_create->codec_type,
                                                  !!(stream_create->flags & SPICE_STREAM_FLAGS_TOP_DOWN),
                                                  stream_create->stream_width,
                                                  stream_create->stream_height,
                                                  stream_create->src_width,
                                                  stream_create->src_height,
                                                  &stream_create->dest,
                                                  stream_create->clip.type,
                                                  num_clip_rects,
                                                  clip_rects);
    _streams[stream_create->id]->next = _active_streams;
    _active_streams = _streams[stream_create->id];
}
示例#18
0
文件: funcserver.c 项目: khalilH/PC2R
/* validation de l'annonce d'une solution par le serveur, fin de la phase de reflexion */
void tuastrouve(char *name, int coups){  
  pthread_mutex_lock(&mutex_clients);
  client_list *aux = clients;
  client_list *user = get_client(clients, name);

  /* Notification à l'utilisateur */
  write(user->socket, "TUASTROUVE/\n", strlen("TUASTROUVE/\n"));
  
  /* Mise à jour des information du client */
  while(aux != NULL){
    if(strcmp(aux->name, name) == 0){
      aux->proposition = coups;
      user->proposition = coups;
      break;
    }
    aux = aux->next;
  }
  pthread_mutex_unlock(&mutex_clients);      

  /* joueur_solution = 1 (une solution a été trouvée) */
  pthread_mutex_lock(&mutex_joueur_solution);
  joueur_solution = 1;
  pthread_mutex_unlock(&mutex_joueur_solution);

  /* Annonce qu'une solution a été trouvée */
  ilatrouve(name, coups);
  
}
示例#19
0
static int
message_begin_cb(http_parser *p)
{
    request *req = NULL;
    PyObject *environ = NULL;
    client_t *client = get_client(p);

    DEBUG("message_begin_cb");

    req = new_request();
    if(req == NULL){
        return -1;
    }
    req->start_msec = current_msec;
    client->current_req = req;
    environ = new_environ(client);
    client->complete = 0;
    /* client->bad_request_code = 0; */
    /* client->body_type = BODY_TYPE_NONE; */
    /* client->body_readed = 0; */
    /* client->body_length = 0; */
    req->environ = environ;
    push_request(client->request_queue, client->current_req);
    return 0;
}
示例#20
0
int
query_string_cb (http_parser *p, const char *buf, size_t len, char partial)
{
  client_t *client = get_client(p);
  request *req = client->req;
  buffer_result ret = MEMORY_ERROR;

  if(req->query_string){
    ret = write2buf(req->query_string, buf, len);
  }else{
    req->query_string = new_buffer(1024*2, LIMIT_QUERY_STRING);
    ret = write2buf(req->query_string, buf, len);
  }
  switch(ret){
  case MEMORY_ERROR:
    client->bad_request_code = 500;
    return -1;
  case LIMIT_OVER:
    client->bad_request_code = 400;
    return -1;
  default:
    break;
  }
  return 0;
}
示例#21
0
int oo_hw_filter_set_thc(struct oo_hw_filter* oofilter,
                         tcp_helper_cluster_t* thc, int protocol,
                         unsigned daddr, int dport,
                         unsigned hwport_mask)
{
  struct efx_filter_spec spec;
  int hwport, base_vi_id, rc;

  ci_assert_equal(oofilter->trs, NULL);
  oofilter->thc = thc;
  for( hwport = 0; hwport < CI_CFG_MAX_REGISTER_INTERFACES; ++hwport )
    if( hwport_mask & (1 << hwport) && thc->thc_vi_set[hwport] != NULL ) {
      base_vi_id = efrm_vi_set_get_base(thc->thc_vi_set[hwport]);
      efx_filter_init_rx(&spec, EFX_FILTER_PRI_REQUIRED,
                         EFX_FILTER_FLAG_RX_SCATTER | EFX_FILTER_FLAG_RX_RSS,
                         base_vi_id);
      spec.rss_context = efrm_vi_set_get_rss_context(thc->thc_vi_set[hwport]);
#if EFX_DRIVERLINK_API_VERSION >= 15
      {
        int stack_id = tcp_helper_cluster_vi_hw_stack_id(thc, hwport);
        ci_assert( stack_id >= 0 );
        efx_filter_set_stack_id(&spec, stack_id);
      }
#endif
      rc = efx_filter_set_ipv4_local(&spec, protocol, daddr, dport);
      ci_assert_equal(rc, 0);
      rc = efrm_filter_insert(get_client(hwport), &spec, false);
      if( rc < 0 ) {
        oo_hw_filter_clear(oofilter);
        return rc;
      }
      oofilter->filter_id[hwport] = rc;
    }
  return 0;
}
示例#22
0
gboolean
sb_settings_get_follow_moves (void)
{
	return gconf_client_get_bool (get_client (),
				      "/apps/source-browser/follow-moves",
				      NULL);
}
示例#23
0
int
body_cb (http_parser *p, const char *buf, size_t len, char partial)
{
  client_t *client = get_client(p);
  if(max_content_length <= client->body_readed + len){
    client->bad_request_code = 413;
    return -1;
  }
  if(client->body_type == BODY_TYPE_NONE){
    if(client->body_length == 0){
      //Length Required
      client->bad_request_code = 411;
      return -1;
    }
    //default memory stream
#ifdef DEBUG
    printf("client->body_length %d \n", client->body_length);
#endif
    client->body_type = BODY_TYPE_BUFFER;
#ifdef DEBUG
    printf("BODY_TYPE_BUFFER \n");
#endif
  }
  write_body(client, buf, len);
  return 0;
}
示例#24
0
void
HTTP_Client_Connection::on_read_error(const error_code& error)
{
	//ACE_OS::printf("read error:%s\n", error.message().c_str()); //@
	//ACE_OS::printf("R");
	++get_client().n_re;
}
示例#25
0
int
header_value_cb (http_parser *p, const char *buf, size_t len, char partial)
{
  uint32_t i;
  header *h;
  client_t *client = get_client(p);
  request *req = client->req;
    
  buffer_result ret = MEMORY_ERROR;
  i = req->num_headers;
  h = req->headers[i];
  
  if(h){
    ret = write2buf(h->value, buf, len);
  }
  switch(ret){
  case MEMORY_ERROR:
    client->bad_request_code = 500;
    return -1;
  case LIMIT_OVER:
    client->bad_request_code = 400;
    return -1;
  default:
    break;
  }
  req->last_header_element = VAL;
  return 0;
}
示例#26
0
文件: funcserver.c 项目: khalilH/PC2R
/* traitement d'une enchere */
void traitement_enchere(char *name, int coups){
  pthread_mutex_lock(&mutex_clients);
  client_list *cl = get_client(clients, name);
  
  if(cl->proposition != -1 && coups >= cl->proposition){
    /* Echec si un joueur essaye d'encherir une valeur plus grande que celle qu'il a déjà encheri */
    echec(cl->socket, name);
  }else{
    client_list *aux = clients;
    int bool = 0;
    char *user_incoherent;
    
    /* Vérification qu'il n'existe pas une enchere de même valeur */
    while(aux != NULL){
      if(aux->proposition == coups){
	user_incoherent = aux->name;
	bool = 1;
	break;
      }
      aux = aux->next;
    }

    if(bool == 1){
      /* Echec */      
      echec(cl->socket, user_incoherent);
    }else{
示例#27
0
int
fragment_cb (http_parser *p, const char *buf, size_t len, char partial)
{
  client_t *client = get_client(p);
  register request *req = client->req;
  buffer_result ret = MEMORY_ERROR;
  
  if(req->fragment){
    ret = write2buf(req->fragment, buf, len);
  }else{
    req->fragment = new_buffer(1024, LIMIT_FRAGMENT);
    ret = write2buf(req->fragment, buf, len);
  }
  switch(ret){
  case MEMORY_ERROR:
    client->bad_request_code = 500;
    return -1;
  case LIMIT_OVER:
    client->bad_request_code = 400;
    return -1;
  default:
    break;
  }
  return 0;
}
示例#28
0
gboolean
gs_plugin_app_install (GsPlugin *plugin,
		       GsApp *app,
		       GCancellable *cancellable,
		       GError **error)
{
	g_autoptr(SnapdClient) client = NULL;
	SnapdInstallFlags flags = SNAPD_INSTALL_FLAGS_NONE;

	/* We can only install apps we know of */
	if (g_strcmp0 (gs_app_get_management_plugin (app), "snap") != 0)
		return TRUE;

	client = get_client (plugin, error);
	if (client == NULL)
		return FALSE;

	gs_app_set_state (app, AS_APP_STATE_INSTALLING);
	if (g_strcmp0 (gs_app_get_metadata_item (app, "snap::confinement"), "classic") == 0)
		flags |= SNAPD_INSTALL_FLAGS_CLASSIC;
	if (!snapd_client_install2_sync (client, flags, gs_app_get_metadata_item (app, "snap::name"), NULL, NULL, progress_cb, app, cancellable, error)) {
		gs_app_set_state_recover (app);
		snapd_error_convert (error);
		return FALSE;
	}
	gs_app_set_state (app, AS_APP_STATE_INSTALLED);
	return TRUE;
}
示例#29
0
gboolean
sb_settings_get_ignore_whitespaces (void)
{
	return gconf_client_get_bool (get_client (),
				      "/apps/source-browser/ignore-whitespaces",
				      NULL);
}
示例#30
0
// Check if an app is graphical by checking if it uses a known GUI interface.
// This doesn't necessarily mean that every binary uses this interfaces, but is probably true.
// https://bugs.launchpad.net/bugs/1595023
static gboolean
is_graphical (GsPlugin *plugin, GsApp *app, GCancellable *cancellable)
{
	g_autoptr(SnapdClient) client = NULL;
	g_autoptr(GPtrArray) plugs = NULL;
	guint i;
	g_autoptr(GError) error = NULL;

	client = get_client (plugin, &error);
	if (client == NULL)
		return FALSE;

	if (!snapd_client_get_interfaces_sync (client, &plugs, NULL, cancellable, &error)) {
		g_warning ("Failed to check interfaces: %s", error->message);
		return FALSE;
	}

	for (i = 0; i < plugs->len; i++) {
		SnapdPlug *plug = plugs->pdata[i];
		const gchar *interface;

		// Only looks at the plugs for this snap
		if (g_strcmp0 (snapd_plug_get_snap (plug), gs_app_get_metadata_item (app, "snap::name")) != 0)
			continue;

		interface = snapd_plug_get_interface (plug);
		if (interface == NULL)
			continue;

		if (g_strcmp0 (interface, "unity7") == 0 || g_strcmp0 (interface, "x11") == 0 || g_strcmp0 (interface, "mir") == 0)
			return TRUE;
	}

	return FALSE;
}