Exemplo n.º 1
0
void RedClient::handle_init(RedPeer::InMessage* message)
{
    SpiceMsgMainInit *init = (SpiceMsgMainInit *)message->data();
    LOG_INFO("");
    _connection_id = init->session_id;
    set_mm_time(init->multi_media_time);
    if (!_during_migration) {
        calc_pixmap_cach_and_glz_window_size(init->display_channels_hint, init->ram_hint);
    }
    set_mouse_mode(init->supported_mouse_modes, init->current_mouse_mode);
    _agent_tokens = init->agent_tokens;
    _agent_connected = !!init->agent_connected;
    if (_agent_connected) {
        Message* msg = new Message(SPICE_MSGC_MAIN_AGENT_START);
        SpiceMsgcMainAgentStart agent_start;
        agent_start.num_tokens = ~0;
        _marshallers->msgc_main_agent_start(msg->marshaller(), &agent_start);
        post_message(msg);
        send_agent_announce_capabilities(true);
    }

    if (!_during_migration) {
        if (!init_guest_display()) {
            send_main_attach_channels();
        }
    } else {
        LOG_INFO("connecting all channels after migration");
        Channels::iterator iter = _channels.begin();
        for (; iter != _channels.end(); ++iter) {
            (*iter)->connect_migration_target();
        }
        _during_migration = false;
    }
}
Exemplo n.º 2
0
void RedChannel::handle_ping(RedPeer::InMessage* message)
{
    SpiceMsgPing *ping = (SpiceMsgPing *)message->data();
    Message *pong = new Message(SPICE_MSGC_PONG);
    _marshallers->msgc_pong(pong->marshaller(), ping);
    post_message(pong);
}
Exemplo n.º 3
0
void RedClient::set_mouse_mode(uint32_t supported_modes, uint32_t current_mode)
{
    if (current_mode != _mouse_mode) {
        _mouse_mode = current_mode;
        Lock lock(_channels_lock);
        Channels::iterator iter = _channels.begin();
        for (; iter != _channels.end(); ++iter) {
            if ((*iter)->get_type() == SPICE_CHANNEL_CURSOR) {
                ((CursorChannel *)(*iter))->on_mouse_mode_change();
            }
        }
        AutoRef<MouseModeEvent> event(new MouseModeEvent(*this));
        push_event(*event);
    }
    // FIXME: use configured mouse mode (currently, use client mouse mode if supported by server)
    if ((supported_modes & SPICE_MOUSE_MODE_CLIENT) && (current_mode != SPICE_MOUSE_MODE_CLIENT)) {
        Message* message = new Message(SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST);
        SpiceMsgcMainMouseModeRequest mouse_mode_request;
        mouse_mode_request.mode = SPICE_MOUSE_MODE_CLIENT;
	_marshallers->msgc_main_mouse_mode_request(message->marshaller(),
						    &mouse_mode_request);

        post_message(message);
    }
}
Exemplo n.º 4
0
void RedChannel::on_message_recived()
{
    if (_message_ack_count && !--_message_ack_count) {
        post_message(new Message(SPICE_MSGC_ACK));
        _message_ack_count = _message_ack_window;
    }
}
Exemplo n.º 5
0
void RedClient::send_agent_announce_capabilities(bool request)
{
    Message* message = new Message(SPICE_MSGC_MAIN_AGENT_DATA);
    VDAgentMessage* msg = (VDAgentMessage*)
        spice_marshaller_reserve_space(message->marshaller(),
                                       sizeof(VDAgentMessage));
    VDAgentAnnounceCapabilities* caps;

    msg->protocol = VD_AGENT_PROTOCOL;
    msg->type = VD_AGENT_ANNOUNCE_CAPABILITIES;
    msg->opaque = 0;
    msg->size = sizeof(VDAgentAnnounceCapabilities) + VD_AGENT_CAPS_BYTES;

    caps = (VDAgentAnnounceCapabilities*)
        spice_marshaller_reserve_space(message->marshaller(), msg->size);

    caps->request = request;
    memset(caps->caps, 0, VD_AGENT_CAPS_BYTES);
    VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_MOUSE_STATE);
    VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_MONITORS_CONFIG);
    VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_REPLY);
    VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_DISPLAY_CONFIG);
    VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);
    ASSERT(_agent_tokens)
    _agent_tokens--;
    post_message(message);
}
void RecordChannel::push_frame(uint8_t *frame)
{
    RecordSamplesMessage *message;
    ASSERT(_frame_bytes == FRAME_SIZE * 4);
    if (!(message = get_message())) {
        DBG(0, "blocked");
        return;
    }
    uint8_t celt_buf[CELT_COMPRESSED_FRAME_BYTES];
    int n;

    if (_mode == SPICE_AUDIO_DATA_MODE_CELT_0_5_1) {
        n = celt051_encode(_celt_encoder, (celt_int16_t *)frame, NULL, celt_buf,
                           CELT_COMPRESSED_FRAME_BYTES);
        if (n < 0) {
            THROW("celt encode failed");
        }
        frame = celt_buf;
    } else {
        n = _frame_bytes;
    }
    RedPeer::OutMessage& peer_message = message->peer_message();
    peer_message.reset(SPICE_MSGC_RECORD_DATA);
    SpiceMsgcRecordPacket packet;
    packet.time = get_mm_time();
    _marshallers->msgc_record_data(peer_message.marshaller(), &packet);
    spice_marshaller_add(peer_message.marshaller(), frame, n);
    post_message(message);
}
Exemplo n.º 7
0
/* wake anybody waiting on the socket event or send the associated message */
static void sock_wake_up( struct sock *sock )
{
    unsigned int events = sock->pmask & sock->mask;
    int i;

    if ( !events ) return;

    if (sock->event)
    {
        if (debug_level) fprintf(stderr, "signalling events %x ptr %p\n", events, sock->event );
        set_event( sock->event );
    }
    if (sock->window)
    {
        if (debug_level) fprintf(stderr, "signalling events %x win %08x\n", events, sock->window );
        for (i = 0; i < FD_MAX_EVENTS; i++)
        {
            int event = event_bitorder[i];
            if (sock->pmask & (1 << event))
            {
                lparam_t lparam = (1 << event) | (sock_get_error(sock->errors[event]) << 16);
                post_message( sock->window, sock->message, sock->wparam, lparam );
            }
        }
        sock->pmask = 0;
        sock_reselect( sock );
    }
}
Exemplo n.º 8
0
/*
    poll_joystick()

    Poll the current state of one given handset joystick.
    num: number of the joystick to poll (0-3)
    Returns true if the handset state has changed and a message was posted.
*/
bool ti99_handset_device::poll_joystick(int num)
{
	uint8_t current_joy;
	int current_joy_x, current_joy_y;
	int message;
	/* read joystick position */
	current_joy_x = ioport(joynames[0][num])->read();
	current_joy_y = ioport(joynames[1][num])->read();

	/* compare with last saved position */
	current_joy = current_joy_x | (current_joy_y << 4);
	if (current_joy != previous_joy[num])
	{
		/* save position */
		previous_joy[num] = current_joy;

		/* transform position to signed quantity */
		current_joy_x -= 7;
		current_joy_y -= 7;

		message = 0;

		/* set sign */
		// note that we set the sign if the joystick position is 0 to work
		// around a bug in the ti99/4 ROMs
		if (current_joy_x <= 0)
		{
			message |= 0x040;
			current_joy_x = - current_joy_x;
		}

		if (current_joy_y <= 0)
		{
			message |= 0x400;
			current_joy_y = - current_joy_y;
		}

		/* convert absolute values to Gray code and insert in message */
		if (current_joy_x & 4)
			current_joy_x ^= 3;
		if (current_joy_x & 2)
			current_joy_x ^= 1;
		message |= current_joy_x << 3;

		if (current_joy_y & 4)
			current_joy_y ^= 3;
		if (current_joy_y & 2)
			current_joy_y ^= 1;
		message |= current_joy_y << 7;

		/* set joystick address */
		message |= (num << 1) | 0x1;

		/* post message */
		post_message(message);
		return true;
	}
	return false;
}
Exemplo n.º 9
0
static ParseAction mpegts_demuxer_read_frame(MpegTSDemuxer *demuxer)
{
    ParseAction   result = PA_READ_FRAME;
    GstFlowReturn flow_result = GST_FLOW_OK;
    AVPacket      packet;
    int           ret = av_read_frame(demuxer->context, &packet);

    switch(ret)
    {
        case 0:
#ifdef ENABLE_VIDEO
            if (packet.stream_index == demuxer->video.stream_index) // Video
                flow_result = process_video_packet(demuxer, &packet);
            else
#endif // ENABLE_VIDEO
            if (packet.stream_index == demuxer->audio.stream_index) // Audio
                flow_result = process_audio_packet(demuxer, &packet);

            if (flow_result != GST_FLOW_OK)
            {
                if (flow_result != GST_FLOW_FLUSHING)
                    post_message(demuxer, "Send packet failed", GST_MESSAGE_ERROR, GST_STREAM_ERROR, GST_STREAM_ERROR_DEMUX);

                result = PA_STOP;
            }
#ifdef FAKE_ERROR
            else if (demuxer->read_bytes > 1000000)
            {
                post_message(demuxer, "Fake error", GST_MESSAGE_ERROR, GST_STREAM_ERROR, GST_STREAM_ERROR_DEMUX);
                result = PA_STOP;
            }
#endif
            break;

        default:
            if (demuxer->is_eos && demuxer->is_last_buffer_send) // Send EOS
                mpegts_demuxer_push_to_sources(demuxer, gst_event_new_eos());
            else
                post_error(demuxer, "LibAV stream parse error", ret, GST_STREAM_ERROR_DEMUX); // Send Error
            result = PA_STOP;
            break;
    }

    av_free_packet(&packet);
    return result;
}
Exemplo n.º 10
0
void RecordChannel::send_start_mark()
{
    Message* message = new Message(SPICE_MSGC_RECORD_START_MARK);
    SpiceMsgcRecordStartMark start_mark;
    start_mark.time = get_mm_time();
    _marshallers->msgc_record_start_mark(message->marshaller(), &start_mark);
    post_message(message);
}
Exemplo n.º 11
0
void RedClient::send_main_attach_channels(void)
{
    if (_msg_attach_channels_sent)
        return;

    post_message(new Message(SPICE_MSGC_MAIN_ATTACH_CHANNELS));
    _msg_attach_channels_sent = true;
}
Exemplo n.º 12
0
void RedChannel::handle_set_ack(RedPeer::InMessage* message)
{
    SpiceMsgSetAck* ack = (SpiceMsgSetAck*)message->data();
    _message_ack_window = _message_ack_count = ack->window;
    Message *response = new Message(SPICE_MSGC_ACK_SYNC);
    SpiceMsgcAckSync sync;
    sync.generation = ack->generation;
    _marshallers->msgc_ack_sync(response->marshaller(), &sync);
    post_message(response);
}
Exemplo n.º 13
0
void RedClient::send_agent_monitors_config()
{
    AutoRef<MonitorsQuery > qury(new MonitorsQuery());
    push_event(*qury);
    (*qury)->wait();
    if (!(*qury)->success()) {
        THROW(" monitors query failed");
    }

    double min_distance = INFINITY;
    int dx = 0;
    int dy = 0;
    int i;

    std::vector<MonitorInfo>& monitors = (*qury)->get_monitors();
    std::vector<MonitorInfo>::iterator iter = monitors.begin();
    for (; iter != monitors.end(); iter++) {
        double distance = sqrt(pow((double)(*iter).position.x, 2) + pow((double)(*iter).position.y,
                                                                        2));
        if (distance < min_distance) {
            min_distance = distance;
            dx = -(*iter).position.x;
            dy = -(*iter).position.y;
        }
    }

    Message* message = new Message(SPICE_MSGC_MAIN_AGENT_DATA);
    VDAgentMessage* msg = (VDAgentMessage*)
      spice_marshaller_reserve_space(message->marshaller(), sizeof(VDAgentMessage));
    msg->protocol = VD_AGENT_PROTOCOL;
    msg->type = VD_AGENT_MONITORS_CONFIG;
    msg->opaque = 0;
    msg->size = sizeof(VDAgentMonitorsConfig) + monitors.size() * sizeof(VDAgentMonConfig);

    VDAgentMonitorsConfig* mon_config = (VDAgentMonitorsConfig*)
      spice_marshaller_reserve_space(message->marshaller(),
				     sizeof(VDAgentMonitorsConfig) + monitors.size() * sizeof(VDAgentMonConfig));
    mon_config->num_of_monitors = monitors.size();
    mon_config->flags = 0;
    if (Platform::is_monitors_pos_valid()) {
        mon_config->flags = VD_AGENT_CONFIG_MONITORS_FLAG_USE_POS;
    }
    for (iter = monitors.begin(), i = 0; iter != monitors.end(); iter++, i++) {
        mon_config->monitors[i].depth = (*iter).depth;
        mon_config->monitors[i].width = (*iter).size.x;
        mon_config->monitors[i].height = (*iter).size.y;
        mon_config->monitors[i].x = (*iter).position.x + dx;
        mon_config->monitors[i].y = (*iter).position.y + dy;
    }
    ASSERT(_agent_tokens)
    _agent_tokens--;
    post_message(message);
    _agent_mon_config_sent = true;
    _agent_reply_wait_type = VD_AGENT_MONITORS_CONFIG;
}
Exemplo n.º 14
0
void RecordChannel::on_connect()
{
    Message* message = new Message(SPICE_MSGC_RECORD_MODE);
    SpiceMsgcRecordMode mode;
    mode.time = get_mm_time();
    mode.mode = _mode =
      test_capability(SPICE_RECORD_CAP_CELT_0_5_1) ? RecordChannel::data_mode :
                                                                      SPICE_AUDIO_DATA_MODE_RAW;
    _marshallers->msgc_record_mode(message->marshaller(), &mode);
    post_message(message);
}
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);
}
Exemplo n.º 16
0
void RedClient::handle_agent_connected(RedPeer::InMessage* message)
{
    DBG(0, "");
    _agent_connected = true;
    Message* msg = new Message(SPICE_MSGC_MAIN_AGENT_START);
    SpiceMsgcMainAgentStart agent_start;
    agent_start.num_tokens = ~0;
    _marshallers->msgc_main_agent_start(msg->marshaller(), &agent_start);
    post_message(msg);
    send_agent_announce_capabilities(false);

    if (_auto_display_res && !_agent_mon_config_sent) {
        send_agent_monitors_config();
    }
}
Exemplo n.º 17
0
	entity_id world::create_entity(std::string debug_name) {
		entity_id res = entities.allocate(std::ref(*this));

		res->debug_name = debug_name;

#ifdef USE_NAMES_FOR_IDS
		res.set_debug_name(debug_name);
		assert(res.get_debug_name() != "");
#endif

		messages::new_entity_message msg;
		msg.subject = res;
		post_message(msg);

		return res;
	}
Exemplo n.º 18
0
void RedClient::send_agent_display_config()
{
    Message* message = new Message(SPICE_MSGC_MAIN_AGENT_DATA);
    VDAgentMessage* msg = (VDAgentMessage*)
        spice_marshaller_reserve_space(message->marshaller(), sizeof(VDAgentMessage));
    VDAgentDisplayConfig* disp_config;

    DBG(0,"");
    msg->protocol = VD_AGENT_PROTOCOL;
    msg->type = VD_AGENT_DISPLAY_CONFIG;
    msg->opaque = 0;
    msg->size = sizeof(VDAgentDisplayConfig);

    disp_config = (VDAgentDisplayConfig*)
        spice_marshaller_reserve_space(message->marshaller(), sizeof(VDAgentDisplayConfig));

    disp_config->flags = 0;
    disp_config->depth = 0;
    if (_display_setting._disable_wallpaper) {
        disp_config->flags |= VD_AGENT_DISPLAY_CONFIG_FLAG_DISABLE_WALLPAPER;
    }

    if (_display_setting._disable_font_smooth) {
        disp_config->flags |= VD_AGENT_DISPLAY_CONFIG_FLAG_DISABLE_FONT_SMOOTH;
    }

    if (_display_setting._disable_animation) {
        disp_config->flags |= VD_AGENT_DISPLAY_CONFIG_FLAG_DISABLE_ANIMATION;
    }

    if (_display_setting._set_color_depth) {
        disp_config->flags |= VD_AGENT_DISPLAY_CONFIG_FLAG_SET_COLOR_DEPTH;
        disp_config->depth = _display_setting._color_depth;
    }

    ASSERT(_agent_tokens)
    _agent_tokens--;
    post_message(message);
    _agent_disp_config_sent = true;

    if (!_display_setting.is_empty()) {
        _agent_reply_wait_type = VD_AGENT_DISPLAY_CONFIG;
    }
}
Exemplo n.º 19
0
void RedClient::do_send_agent_clipboard()
{
    uint32_t size;

    while (_agent_tokens &&
           (size = MIN(VD_AGENT_MAX_DATA_SIZE,
                       _agent_out_msg_size - _agent_out_msg_pos))) {
        Message* message = new Message(SPICE_MSGC_MAIN_AGENT_DATA);
        void* data = spice_marshaller_reserve_space(message->marshaller(), size);
        memcpy(data, (uint8_t*)_agent_out_msg + _agent_out_msg_pos, size);
        _agent_tokens--;
        post_message(message);
        _agent_out_msg_pos += size;
        if (_agent_out_msg_pos == _agent_out_msg_size) {
            delete[] (uint8_t *)_agent_out_msg;
            _agent_out_msg = NULL;
            _agent_out_msg_size = 0;
            _agent_out_msg_pos = 0;
        }
    }
}
Exemplo n.º 20
0
PostListPage::PostListPage(QWidget* parent) :
  QWidget(parent)
{
  _ui = new Ui::PostListPage;
  _ui->setupUi(this);
  _ui->splitter->setStretchFactor(0, 1);
  _ui->splitter->setStretchFactor(1, 0);
  _ui->splitter->setSizes({10, 1});

  static QList<QString> colors = { "FF9908", "FFBA00", "DD5F5F", "06A3CB", "8ABDB0", "9EC41C" };
  _ui->colorWidget->set_colors(colors);

  _layout = new QVBoxLayout(_ui->postsWidget);
  _layout->setContentsMargins(0, 0, 0, 0);
  _spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
  _layout->addSpacerItem(_spacer);

  connect(_ui->refreshListButton, SIGNAL(clicked()), this, SLOT(refresh_list()));
  connect(_ui->postButton, SIGNAL(clicked()), this, SLOT(post_message()));
  connect(_ui->setLocationButton, SIGNAL(clicked()), this, SIGNAL(show_location_dialog()));
}
Exemplo n.º 21
0
static int lua_post_message(lua_State *L)
{
	void *session;
	const char *nch,*msg;
	int result=LIBIRC_ERR_INVAL;
	if(lua_gettop(L)==3){
		session=lua_touserdata(L,1);
		if(session!=NULL){
			nch=lua_tostring(L,2);
			msg=lua_tostring(L,3);
			if((nch!=NULL) && (msg!=NULL)){
				void *hwnd;
				hwnd=get_hwnd_by_session(session,nch);
				if(hwnd!=0){
					result=post_message(hwnd,msg);
				}
			}
		}
	}
	lua_pushinteger(L,result);
	return 1;
}
Exemplo n.º 22
0
void RedClient::send_agent_clipboard_message(uint32_t message_type, uint32_t size, void* data)
{
    if (!_agent_connected)
        return;

    if (!VD_AGENT_HAS_CAPABILITY(_agent_caps, _agent_caps_size,
                                 VD_AGENT_CAP_CLIPBOARD_BY_DEMAND))
        return;

    Message* message = new Message(SPICE_MSGC_MAIN_AGENT_DATA);
    VDAgentMessage* msg = (VDAgentMessage*)
      spice_marshaller_reserve_space(message->marshaller(), sizeof(VDAgentMessage) + size);
    msg->protocol = VD_AGENT_PROTOCOL;
    msg->type = message_type;
    msg->opaque = 0;
    msg->size = size;
    if (size && data) {
        memcpy(msg->data, data, size);
    }
    ASSERT(_agent_tokens)
    _agent_tokens--;
    post_message(message);
}
Exemplo n.º 23
0
jint Java_pp_compiler_Compile_compiler(JNIEnv* env, jobject obj, jstring jname)
{

	 int e;
	 const char*path;
	 int i;
	 char*name; // index of the file name

     initialize();

	 // error capture
	 e=0;
     if ((e=setjmp(jmp_env))!=0)
     {
    	 terminate();
         if (iStackPtr>0)
    	 {
				#ifdef DEBUG
					 return 12345;  // for debug to stay in console
				#else
					 return e;
				#endif
    		  // lauch editor on the error if e>0
    		  // stay on the console on fatal error <0
    	 }
    	 return -1;
     }

	 // Parameters are used in other functons such as emitChar
     // so save them in globals
	 Env=env;
	 Obj=obj;

	 // compute the identifier of the Java Method used by the compiler
	 jclass cls = (*env)->GetObjectClass(env, obj);
   	 emitcharID = (*env)->GetMethodID(env, cls, "emitChar", "(C)V");
     if (emitcharID == NULL) ReportError(INTERNAL,"method not found");  // Humm, method not found

	 // get the path of the file to compile
     path=(*env)->GetStringUTFChars(env,jname,NULL);
	 if (path==NULL) ReportError(OUTOFMEMORY);       // out of memory

	 // copy the path in the Pool and split it
	 // split the path into the path and the name
	 // a terminal zero is included in place of the last '/'
	 // assign LoPoolMax to the end of the path
	 name=split(path);
     (*env)->ReleaseStringUTFChars(env,jname,path);

     prompt(name);

     do_compile();

     do_link();

     build_exec();

     terminate();

     post_message();

	 return 0;

}
Exemplo n.º 24
0
XCamReturn
DeviceManager::poll_buffer_failed (int64_t timestamp, const char *msg)
{
    post_message (XCAM_MESSAGE_BUF_ERROR, timestamp, msg);
    return XCAM_RETURN_NO_ERROR;
}
static int
callback_messageboard(struct lws *wsi, enum lws_callback_reasons reason,
		      void *user, void *in, size_t len)
{
	struct per_session_data__gs_mb *pss = (struct per_session_data__gs_mb *)user;
	const struct lws_protocol_vhost_options *pvo;
	struct per_vhost_data__gs_mb *vhd = (struct per_vhost_data__gs_mb *)
		lws_protocol_vh_priv_get(lws_get_vhost(wsi), lws_get_protocol(wsi));
	unsigned char *p, *start, *end, buffer[LWS_PRE + 256];
	char s[512];
	int n;

	switch (reason) {
	case LWS_CALLBACK_PROTOCOL_INIT: /* per vhost */
		vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi),
			lws_get_protocol(wsi), sizeof(struct per_vhost_data__gs_mb));
		if (!vhd)
			return 1;
		vhd->vh = lws_get_vhost(wsi);
		vhd->gsp = lws_vhost_name_to_protocol(vhd->vh,
						"protocol-generic-sessions");
		if (!vhd->gsp) {
			lwsl_err("messageboard: requires generic-sessions\n");
			return 1;
		}

		pvo = (const struct lws_protocol_vhost_options *)in;
		while (pvo) {
			if (!strcmp(pvo->name, "message-db"))
				strncpy(vhd->message_db, pvo->value,
					sizeof(vhd->message_db) - 1);
			pvo = pvo->next;
		}
		if (!vhd->message_db[0]) {
			lwsl_err("messageboard: \"message-db\" pvo missing\n");
			return 1;
		}

		if (sqlite3_open_v2(vhd->message_db, &vhd->pdb,
				    SQLITE_OPEN_READWRITE |
				    SQLITE_OPEN_CREATE, NULL) != SQLITE_OK) {
			lwsl_err("Unable to open message db %s: %s\n",
				 vhd->message_db, sqlite3_errmsg(vhd->pdb));

			return 1;
		}
		if (sqlite3_exec(vhd->pdb, "create table if not exists msg ("
				 " idx integer primary key, time integer,"
				 " username varchar(32), email varchar(100),"
				 " ip varchar(80), content blob);",
				 NULL, NULL, NULL) != SQLITE_OK) {
			lwsl_err("Unable to create msg table: %s\n",
				 sqlite3_errmsg(vhd->pdb));

			return 1;
		}

		vhd->last_idx = get_last_idx(vhd);
		break;

	case LWS_CALLBACK_PROTOCOL_DESTROY:
		if (vhd->pdb)
			sqlite3_close(vhd->pdb);
		goto passthru;

	case LWS_CALLBACK_ESTABLISHED:
		vhd->gsp->callback(wsi, LWS_CALLBACK_SESSION_INFO,
				   pss->pss_gs, &pss->sinfo, 0);
		if (!pss->sinfo.username[0]) {
			lwsl_notice("messageboard ws attempt with no session\n");

			return -1;
		}

		lws_callback_on_writable(wsi);
		break;

	case LWS_CALLBACK_SERVER_WRITEABLE:
		{
			struct message m;
			char j[MAX_MSG_LEN + 512], e[MAX_MSG_LEN + 512],
				*p = j + LWS_PRE, *start = p,
				*end = j + sizeof(j) - LWS_PRE;

			if (pss->last_idx == vhd->last_idx)
				break;

			/* restrict to last 10 */
			if (!pss->last_idx)
				if (vhd->last_idx >= 10)
					pss->last_idx = vhd->last_idx - 10;

			sprintf(s, "select idx, time, username, email, ip, content "
				   "from msg where idx > %lu order by idx limit 1;",
				   pss->last_idx);
			if (sqlite3_exec(vhd->pdb, s, lookup_cb, &m, NULL) != SQLITE_OK) {
				lwsl_err("Unable to lookup msg: %s\n",
					 sqlite3_errmsg(vhd->pdb));
				return 0;
			}

			/* format in JSON */
			p += snprintf(p, end - p,
					"{\"idx\":\"%lu\",\"time\":\"%lu\",",
					m.idx, m.time);
			p += snprintf(p, end - p, " \"username\":\"%s\",",
				lws_json_purify(e, m.username, sizeof(e)));
			p += snprintf(p, end - p, " \"email\":\"%s\",",
				lws_json_purify(e, m.email, sizeof(e)));
			p += snprintf(p, end - p, " \"ip\":\"%s\",",
				lws_json_purify(e, m.ip, sizeof(e)));
			p += snprintf(p, end - p, " \"content\":\"%s\"}",
				lws_json_purify(e, m.content, sizeof(e)));

			if (lws_write(wsi, (unsigned char *)start, p - start,
				      LWS_WRITE_TEXT) < 0)
				return -1;

			pss->last_idx = m.idx;
			if (pss->last_idx == vhd->last_idx)
				break;

			lws_callback_on_writable(wsi); /* more to do */
		}
		break;

	case LWS_CALLBACK_HTTP:
		pss->our_form = 0;

		/* ie, it's our messageboard new message form */
		if (!strcmp((const char *)in, "/msg")) {
			pss->our_form = 1;
			break;
		}

		goto passthru;

	case LWS_CALLBACK_HTTP_BODY:
		if (!pss->our_form)
			goto passthru;

		if (len < 2)
			break;
		if (!pss->spa) {
			pss->spa = lws_spa_create(wsi, param_names,
						ARRAY_SIZE(param_names),
						MAX_MSG_LEN + 1024, NULL, NULL);
			if (!pss->spa)
				return -1;
		}

		if (lws_spa_process(pss->spa, in, len)) {
			lwsl_notice("spa process blew\n");
			return -1;
		}
		break;

	case LWS_CALLBACK_HTTP_BODY_COMPLETION:
		if (!pss->our_form)
			goto passthru;

		if (post_message(wsi, vhd, pss))
			return -1;

		p = buffer + LWS_PRE;
		start = p;
		end = p + sizeof(buffer) - LWS_PRE;

		if (lws_add_http_header_status(wsi, 200, &p, end))
			return -1;
		if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE,
				(unsigned char *)"text/plain", 10, &p, end))
			return -1;
		if (lws_add_http_header_content_length(wsi, 1, &p, end))
			return -1;
		if (lws_finalize_http_header(wsi, &p, end))
			return -1;
		n = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS);
		if (n != (p - start)) {
			lwsl_err("_write returned %d from %d\n", n, (p - start));
			return -1;
		}
		s[0] = '0';
		n = lws_write(wsi, (unsigned char *)s, 1, LWS_WRITE_HTTP);
		if (n != 1)
			return -1;

		goto try_to_reuse;

	case LWS_CALLBACK_HTTP_BIND_PROTOCOL:
		if (!pss || pss->pss_gs)
			break;

		pss->pss_gs = malloc(vhd->gsp->per_session_data_size);
		if (!pss->pss_gs)
			return -1;

		memset(pss->pss_gs, 0, vhd->gsp->per_session_data_size);
		break;

	case LWS_CALLBACK_HTTP_DROP_PROTOCOL:
		if (vhd->gsp->callback(wsi, reason, pss ? pss->pss_gs : NULL, in, len))
			return -1;

		if (pss && pss->spa) {
			lws_spa_destroy(pss->spa);
			pss->spa = NULL;
		}
		if (pss && pss->pss_gs) {
			free(pss->pss_gs);
			pss->pss_gs = NULL;
		}
		break;

	default:
passthru:
		return vhd->gsp->callback(wsi, reason, pss ? pss->pss_gs : NULL, in, len);
	}

	return 0;


try_to_reuse:
	if (lws_http_transaction_completed(wsi))
		return -1;

	return 0;
}
Exemplo n.º 26
0
static inline void post_unsupported_warning(MpegTSDemuxer *demuxer)
{
    post_message(demuxer, "Unsupported stream type", GST_MESSAGE_WARNING, GST_STREAM_ERROR, GST_STREAM_ERROR_NOT_IMPLEMENTED);
}
Exemplo n.º 27
0
/*
    poll_keyboard()
    Poll the current state of one given handset keypad.
    num: number of the keypad to poll (0-3)
    Returns true if the handset state has changed and a message was posted.
*/
bool ti99_handset_device::poll_keyboard(int num)
{
	uint32_t key_buf;
	uint8_t current_key;
	int i;

	/* read current key state */
	key_buf = (ioport(keynames[num])->read() | (ioport(keynames[num + 1])->read() << 16) ) >> (4*num);

	// If a key was previously pressed, this key was not shift, and this key is
	// still down, then don't change the current key press.
	if (previous_key[num] !=0 && (previous_key[num] != 0x24)
		&& (key_buf & (1 << (previous_key[num] & 0x1f))))
	{
		/* check the shift modifier state */
		if (((previous_key[num] & 0x20) != 0) == ((key_buf & 0x0008) != 0))
			/* the shift modifier state has not changed */
			return false;
		else
		{
			// The shift modifier state has changed: we need to update the
			// keyboard state
			if (key_buf & 0x0008)
			{   /* shift has been pressed down */
				previous_key[num] = current_key = previous_key[num] | 0x20;
			}
			else
			{
				previous_key[num] = current_key = previous_key[num] & ~0x20;
			}
			/* post message */
			post_message((((unsigned)current_key) << 4) | (num << 1));
			return true;
		}
	}

	current_key = 0;    /* default value if no key is down */
	for (i=0; i<20; i++)
	{
		if (key_buf & (1 << i))
		{
			current_key = i + 1;
			if (key_buf & 0x0008)
				current_key |= 0x20;    /* set shift flag */

			if (current_key != 0x24)
				// If this is the shift key, any other key we may find will
				// have higher priority; otherwise, we may exit the loop and keep
				// the key we have just found.
				break;
		}
	}

	if (current_key != previous_key[num])
	{
		previous_key[num] = current_key;

		/* post message */
		post_message((((unsigned) current_key) << 4) | (num << 1));
		return true;
	}
	return false;
}
Exemplo n.º 28
0
static gboolean mpegts_demuxer_sink_event(GstPad *pad, GstObject *parent, GstEvent *event)
{
    MpegTSDemuxer *demuxer = MPEGTS_DEMUXER(parent);
    gboolean      result = TRUE;

    switch (GST_EVENT_TYPE(event))
    {
        case GST_EVENT_EOS:
#ifdef DEBUG_OUTPUT
            g_print("MpegTS sinkEvent: EOS\n");
#endif
            g_mutex_lock(&demuxer->lock);
            demuxer->is_eos = TRUE;
            g_cond_signal(&demuxer->add_cond); // Signal read callback to read up remaining data.
            g_mutex_unlock(&demuxer->lock);

            gst_event_unref(event);
            break;

        case GST_EVENT_FLUSH_START:
#ifdef DEBUG_OUTPUT
            g_print("MpegTS sinkEvent: FLUSH_START ...");
#endif
            result = gst_pad_event_default(demuxer->sinkpad, parent, event);

            g_mutex_lock(&demuxer->lock);
            demuxer->is_flushing = TRUE;
            g_cond_signal(&demuxer->del_cond); // Signal _chain() and read callback to wake them up and update state.
            g_cond_signal(&demuxer->add_cond);
            g_mutex_unlock(&demuxer->lock);

            if (demuxer->reader_thread)
            {
                g_thread_join(demuxer->reader_thread);
                demuxer->reader_thread = NULL;
            }

#ifdef DEBUG_OUTPUT
            g_print("done.\n");
#endif
            break;

        case GST_EVENT_FLUSH_STOP: // Stop flushing buffers.
            g_mutex_lock(&demuxer->lock);
            mpegts_demuxer_flush(demuxer);
            demuxer->is_flushing = FALSE; // Unset flag so chain function accepts buffers.
            g_mutex_unlock(&demuxer->lock);
            result = gst_pad_event_default(demuxer->sinkpad, parent, event);

#ifdef DEBUG_OUTPUT
            g_print("MpegTS sinkEvent: FLUSH_STOP\n");
#endif
            break;

        case GST_EVENT_SEGMENT:
        {
            GstSegment segment;
            gst_event_copy_segment(event, &segment);
            gst_event_unref(event);

            g_mutex_lock(&demuxer->lock);
            if (!demuxer->is_closing)
            {
#ifdef DEBUG_OUTPUT
                g_print("MpegTS sinkEvent: NEW_SEGMENT, time=%.2f\n",
                        time != GST_CLOCK_TIME_NONE ? (double)time/GST_SECOND : -1.0);
#endif
                if (segment.format == GST_FORMAT_TIME)
                {
                    gst_segment_copy_into(&segment, &demuxer->audio.segment);
                    gst_segment_copy_into(&segment, &demuxer->video.segment);
                }

                demuxer->audio.discont = demuxer->video.discont = TRUE;
                demuxer->is_eos = FALSE;
                demuxer->is_last_buffer_send = FALSE;
                demuxer->is_reading = TRUE;

                if (!demuxer->reader_thread)
                {
                    demuxer->reader_thread = g_thread_new(NULL, mpegts_demuxer_process_input, demuxer);
#ifdef DEBUG_OUTPUT
                    g_print("MpegTS: Process_input thread created\n");
#endif
                }
                else
                    post_message(demuxer, "Demuxer thread is not null", GST_MESSAGE_ERROR, GST_CORE_ERROR, GST_CORE_ERROR_THREAD);
            }
            g_mutex_unlock(&demuxer->lock);
            break;
        }

        default:
            result = mpegts_demuxer_push_to_sources(demuxer, event);
            break;
    }

    return result;
}
Exemplo n.º 29
0
void RedClient::send_migrate_end()
{
    Message* message = new Message(SPICE_MSGC_MAIN_MIGRATE_END);
    post_message(message);
}