예제 #1
0
DataBuffer NetGameNetworkData::send_data(const NetGameEvent &e)
{
	DataBuffer buffer = encode_event(e);
	if (buffer.get_size() > packet_limit + 2)
		throw Exception("Outgoing message too big");
	return buffer;
}
예제 #2
0
파일: esdl_events.c 프로젝트: MTpitre/esdl
void es_peepEvents2(ErlDrvPort port, ErlDrvTermData caller, char *bp)
{  
    SDL_Event events[256];
    int numevents, res, i, sz;
    Uint32 mask;
    char *start;
    ErlDrvBinary * bin;
    ErlDrvTermData rt[8];
    
    mask = * (Uint32 *) bp; bp += sizeof(Uint32);
    numevents = *bp++;
    
    SDL_PumpEvents();
    res = SDL_PeepEvents(events, numevents, SDL_GETEVENT, mask);
    bin = driver_alloc_binary(res*MAX_EVENT_SIZE);
    bp = start = bin->orig_bytes;
    for (i = 0; i < res; i++) {
	bp = encode_event(&(events[i]), bp);
    }
    sz = bp-start;
    rt[0] = ERL_DRV_ATOM; rt[1]=driver_mk_atom((char *) "_esdl_result_");
    rt[2] = ERL_DRV_BINARY; rt[3] = (ErlDrvTermData) bin; rt[4] = sz; rt[5] = 0;
    rt[6] = ERL_DRV_TUPLE; rt[7] = 2;
    driver_send_term(port,caller,rt,8);
    driver_free_binary(bin);
}
예제 #3
0
void es_peepEvents(sdl_data *sd, int len, char *bp)
{
  SDL_Event events[256];
  int numevents, res;
  Uint32 mask;
  char *start;

  if (len == 0) {
    mask = SDL_ALLEVENTS;
    numevents = 16;
  } else {
    mask = * (Uint32 *) bp; bp += sizeof(Uint32);
    numevents = *bp++;
  }
  SDL_PumpEvents();
  res = SDL_PeepEvents(events, numevents, SDL_GETEVENT, mask);
  if (res > 0) {
    int sendlen, i;
    bp = start = sdl_get_temp_buff(sd, res*MAX_EVENT_SIZE);
    for (i = 0; i < res; i++) {
      bp = encode_event(&(events[i]), bp);
    }
    sendlen = bp - start;
    sdl_send(sd, sendlen);
  }
}
예제 #4
0
void es_waitEvent(sdl_data *sd, int len,char *buff)
{
    SDL_Event event;
    int sendlen;
    char *bp, *start;
    
    bp = start = sdl_get_temp_buff(sd, MAX_EVENT_SIZE);
    SDL_WaitEvent(&event);
    bp = encode_event(&event, bp);
    if (*start != SDL_NOEVENT) {
      sendlen = bp - start;
      sdl_send(sd, sendlen);
    }
}
예제 #5
0
void es_pollEvent(sdl_data *sd, int len, char *buff)
{
  SDL_Event event;
  
  if (SDL_PollEvent(&event)) {
    int sendlen;
    char *bp, *start;

    bp = start = sdl_get_temp_buff(sd, MAX_EVENT_SIZE);
    bp = encode_event(&event, bp);
    sendlen = bp - start;
    sdl_send(sd, sendlen);
  }
}
예제 #6
0
파일: esdl_events.c 프로젝트: MTpitre/esdl
void es_waitEvent2(ErlDrvPort port, ErlDrvTermData caller) 
{
    SDL_Event event;
    ErlDrvBinary * bin;
    ErlDrvTermData rt[8];
    char *bp, *start;
    int sz;

    bin = driver_alloc_binary(MAX_EVENT_SIZE);
    bp = start = bin->orig_bytes;
    
    SDL_WaitEvent(&event);
    bp = encode_event(&event, bp);
    
    sz = bp-start;
    rt[0] = ERL_DRV_ATOM; rt[1]=driver_mk_atom((char *) "_esdl_result_");  
    rt[2] = ERL_DRV_BINARY; rt[3] = (ErlDrvTermData) bin; rt[4] = sz; rt[5] = 0;
    rt[6] = ERL_DRV_TUPLE; rt[7] = 2;
    driver_send_term(port,caller,rt,8);
    driver_free_binary(bin);
}
예제 #7
0
void pub_cb (flux_t *h, flux_msg_handler_t *mh,
             const flux_msg_t *msg, void *arg)
{
    struct publisher *pub = arg;
    const char *topic;
    const char *payload = NULL; // optional
    int flags;
    uint32_t rolemask, userid;
    flux_msg_t *event = NULL;

    if (flux_request_unpack (msg, NULL, "{s:s s:i s?:s}",
                                        "topic", &topic,
                                        "flags", &flags,
                                        "payload", &payload) < 0)
        goto error;
    if ((flags & ~(FLUX_MSGFLAG_PRIVATE)) != 0) {
        errno = EPROTO;
        goto error;
    }
    if (flux_msg_get_rolemask (msg, &rolemask) < 0)
        goto error;
    if (flux_msg_get_userid (msg, &userid) < 0)
        goto error;
    if (!(event = encode_event (topic, flags, rolemask, userid,
                                ++pub->seq, payload)))
        goto error_restore_seq;
    send_event (pub, event);
    if (flux_respond_pack (h, msg, "{s:i}", "seq", pub->seq) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    flux_msg_destroy (event);
    return;
error_restore_seq:
    pub->seq--;
error:
    if (flux_respond (h, msg, errno, NULL) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    flux_msg_destroy (event);
}