示例#1
0
/*
** close_output
**
** close output file, if it not stdout
*/
VOID close_output( VOID )
{
    if ( outfile ) {

        if ( (return_code == RC_OK)
             || (return_code == RC_WARN)
             || debug )
        {

            status_msg( "Writting output" );
            errno = 0;
            outfclose( outfile );
            if ( errno )
                err_write( outfile );
            status_clear();

        } else {

            status_msg( "No output written" );
            status_lf();
            outfclear( outfile );

        }
    }
}
void QuadDecodeMsg::serial_callback(const quadrotor_msgs::Serial::ConstPtr &msg)
{
    if(msg->type == quadrotor_msgs::Serial::OUTPUT_DATA)
    {
        quadrotor_msgs::OutputData::Ptr output_msg(new quadrotor_msgs::OutputData);
        sensor_msgs::Imu::Ptr imu_msg(new sensor_msgs::Imu);

        if(quadrotor_msgs::decodeOutputData(msg->data, *output_msg))
        {
            output_msg->header.stamp = msg->header.stamp;
            output_msg->header.frame_id = "/quadrotor";
            output_data_pub_.publish(output_msg);

            imu_msg->header = output_msg->header;
            imu_msg->orientation = output_msg->orientation;
            imu_msg->angular_velocity = output_msg->angular_velocity;
            imu_msg->linear_acceleration = output_msg->linear_acceleration;
            imu_output_pub_.publish(imu_msg);
        }
    }
    else if(msg->type == quadrotor_msgs::Serial::STATUS_DATA)
    {
        quadrotor_msgs::StatusData::Ptr status_msg(new quadrotor_msgs::StatusData);
        if(quadrotor_msgs::decodeStatusData(msg->data, *status_msg))
        {
            status_msg->header.stamp = msg->header.stamp;
            status_msg->header.frame_id = "/quadrotor";
            status_pub_.publish(status_msg);
        }
    }
}
示例#3
0
int
Bounded_Packet_Relay::report_statistics (void)
{
  // Serialize access to start and end transmission calls,
  // statistics reporting calls.
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->transmission_lock_, -1);

  // If a transmission is already in progress, just return.
  if (is_active_)
    return 1;

  // Calculate duration of trasmission.
  ACE_Time_Value duration (transmission_end_);
  duration -= transmission_start_;

  // Report transmission statistics.
  ACE_DEBUG ((LM_DEBUG,
              "\n\nStatisics for transmission %u:\n\n"
              "Transmission status: %s\n"
              "Start time:          %d (sec) %d (usec)\n"
              "End time:            %d (sec) %d (usec)\n"
              "Duration:            %d (sec) %d (usec)\n"
              "Packets relayed:     %u\n\n",
              transmission_number_, status_msg (),
              transmission_start_.sec (),
              transmission_start_.usec (),
              transmission_end_.sec (),
              transmission_end_.usec (),
              duration.sec (),
              duration.usec (),
              packets_sent_));
  return 0;
}
示例#4
0
文件: server.c 项目: jonsafari/mocp
void update_eq_name()
{
	char buffer[27];

	char *n = equalizer_current_eqname();

	int l = strlen(n);

	/* Status message can only take strings up to 25 chars
	 * (Without terminating zero).
	 * The message header has 11 chars (EQ set to...).
	 */
	if (l > 14)
	{
		n[14] = 0;
		n[13] = '.';
		n[12] = '.';
		n[11] = '.';
	}

	sprintf(buffer, "EQ set to: %s", n);

	logit("%s", buffer);

	free(n);

	status_msg(buffer);
}
示例#5
0
/*
** status_infile
**
** display input file status (filename & line-count)
**
** params: f......input file to display message about
**         force..display message in any case
*/
int status_infile( INFILE *f, BOOL force )
{
    char buf[MAXLINELEN];
    int  ctr = 0;

    if (f) {

        if ( prev_stfile != f )
            prev_stline = 0;

        force |= ( (prev_stfile != f)
                   || ( (infget_y(f)-prev_stline) > ST_LINE_QUANTUM )
                 );

        if (force) {

            sprintf( buf, "%s (%d)", infget_fname(f), infget_y(f) );
            ctr = status_msg( buf );
            prev_stline = infget_y(f);
            prev_stfile = f;

        }

    }

    return ctr;


}
示例#6
0
/*
 * status_error
 *
 * display error status messages
 */
VOID status_error(STRPTR s)
{
    strncpy(status_buf, "*** ", MAX_STATUSLEN);
    strncat(status_buf, s, MAX_STATUSLEN - strlen(status_buf));
    status_msg(status_buf);
    status_lf();
    set_return_code(RC_ERROR);
}
示例#7
0
文件: server.c 项目: jonsafari/mocp
void req_equalizer_refresh()
{
	equalizer_refresh();

	status_msg("Equalizer refreshed");

	logit("Equalizer refreshed");
}
示例#8
0
文件: aifled.c 项目: Simmiyy/aifled
void fork_program()
{
    pid_t program_pid;

    status_msg("about to fork...",3);
    program_pid = fork();

    sprintf(szMsg,"done forking, return value: %d", program_pid);
    status_msg(szMsg,3);

    // check for fork error
    if(program_pid == -1)
    {
        status_msg("unable to fork program",1);
        freakout("Unable to fork program.");
    }
    // stop execution of parent process, but leave child running...
    if(program_pid != 0)
    {

// Simmiyy - The father process create the PID file and exit
        FILE *f = NULL;
        if((f = fopen( szPidFile, "w")) != NULL) {
            fprintf( f, "%d", program_pid );
            fclose(f);
        }

        status_msg("parent process terminating...",1);
        _exit(0);

// Simmiyy - Create a session and disconnect the child from controlling tty
    } else {

        setsid();
#ifdef TIOCNOTTY
        int fd_tty;
        if((fd_tty = open("/dev/tty", O_RDWR | O_NOCTTY)) != -1) {
            ioctl(fd_tty, TIOCNOTTY, NULL);
            close(fd_tty);
            status_msg("disconnected from controlling tty...",3);
        }
#endif
    }
}
示例#9
0
文件: server.c 项目: jonsafari/mocp
void req_toggle_make_mono()
{
	char buffer[128];

	softmixer_set_mono(!softmixer_is_mono());

	sprintf(buffer, "Mono-Mixing set to: %s", softmixer_is_mono()?"on":"off");

	status_msg(buffer);
}
示例#10
0
/*
 * status_file_end
 *
 * hsc-callback for file fully processed: display
 * file and total number of line, perform liefeed
 */
VOID status_file_begin(HSCPRC * hp, STRPTR filename)
{
    if (filename) {
        /* create status-string: "<filename> (reading)" */
        /* NOTE: this is not done via sprintf(), because
         *   no check for a too long string would be done */
        strncpy(status_buf, filename, MAX_STATUSLEN);
        strncat(status_buf, " (reading)", MAX_STATUSLEN - strlen(status_buf));
        status_msg(status_buf);
    }
}
示例#11
0
/*
 * status_misc
 *
 * display misc. status messages
 */
VOID status_misc(HSCPRC * hp, STRPTR s)
{
    if (disp_status_verbose) {

        strcpy(status_buf, "");
#if 0
        status_file_and_line(hp);
#endif
        strncat(status_buf, s, MAX_STATUSLEN - strlen(status_buf));
        status_msg(status_buf);
        status_lf();

    }
}
示例#12
0
/*
 * status_line
 */
VOID status_line(HSCPRC * hp)
{
    if (disp_status_line
#if 1
            /* set this to '0' to see every line displayed in status */
            && ((hsc_get_file_line(hp) - prev_status_line) > ST_LINE_QUANTUM)
#endif
       ) {

        status_file_and_line(hp);
        status_msg(status_buf);
        prev_status_line = hsc_get_file_line(hp);

    }
}
示例#13
0
int
Bounded_Packet_Relay::end_transmission (Transmission_Status status)
{
  // Serialize access to start and end transmission calls,
  // statistics reporting calls.
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->transmission_lock_, -1);

  // If a transmission is not already in progress, just return.
  if (! is_active_)
    return 1;

  // Set transmission in progress flag false.
  is_active_ = 0;

  // Ask the the input thread to stop.
  if (input_wrapper_->request_stop () < 0)
    {
      status_ = ERROR_DETECTED;
      transmission_end_ = ACE_OS::gettimeofday ();
      ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
                         "failed asking input device thread to stop"),
                        -1);
    }

  // Deactivate the queue, allowing all waiting threads to continue.
  queue_.deactivate ();

  // Wait for input thread to stop.
  input_task_mgr_->wait_task (input_wrapper_);

  // Reactivate the queue, and then clear it.
  queue_.activate ();
  while (! queue_.is_empty ())
    {
      ACE_Message_Block *msg;
      queue_.dequeue_head (msg);
      delete msg;
    }

  // If all went well, set passed status, stamp end time, print a
  // termination message, and return success.
  status_ = status;
  transmission_end_ = ACE_OS::gettimeofday ();
  ACE_DEBUG ((LM_DEBUG,
              "\n\nTransmission %u ended with status: %s\n\n",
              transmission_number_, status_msg ()));
  return 0;
}
/*
 * load and send headers
 */
int send_headers(const int fd, const resp_hdrs* hdrs) {
  /* HTTP/1.1 200 OK  */
  char hbuf[100] = "HTTP/";
  strcat(hbuf, hdrs->version);
  strcat(hbuf, status_msg(hdrs->status_code));
  strcat(hbuf, "\r\n");
  send_msg(fd, hbuf);
  /********************/

  /* Server: SBGiP/0.1    */
  char rbuf[100] = "Server: ";
  strcat(rbuf, hdrs->server);
  strcat(rbuf, "\r\n");
  send_msg(fd, rbuf);
  /************************/

  /* Content-Type: text/html  */
  char ibuf[100] = "Content-Type: ";
  strcat(ibuf, hdrs->content_type);
  strcat(ibuf, "\r\n");
  send_msg(fd, ibuf);
  /****************************/

  /* Content-Length: 100  */
  char obuf[100] = "Content-Type: ";

  char len[20];
  sprintf(len, "%d", (int)hdrs->content_length);
  strcat(obuf, len);

  strcat(obuf, "\r\n");
  send_msg(fd, obuf);
  /************************/

  /* Last-Modified: Fri, 31 Dec 1999 23:59:59 GMT */
  char pbuf[100] = "Last-Modified: ";
  char tbuf[30];
  datetime(hdrs->last_modified, tbuf);
  strcat(pbuf, tbuf);
  strcat(pbuf, "\r\n\r\n");
  send_msg(fd, pbuf);
  /************************************************/

  return 0;
}
示例#15
0
/*
 * status_file_and_line
 *
 * copy status message for current file & line
 * processing into status_buf[]
 *
 * NOTE: messages >79 chars are truncated
 */
static VOID status_file_and_line(HSCPRC * hp)
{
    STRPTR filename = hsc_get_file_name(hp);

    if (filename) {
        /* create status-string */
        /* NOTE: this is not done via sprintf(), because
         *   no check for a too long string would be done */
        strncpy(status_buf, filename, MAX_STATUSLEN);
        strncat(status_buf, " (", MAX_STATUSLEN - strlen(status_buf));
        strncat(status_buf, long2str(hsc_get_file_line(hp)),
                MAX_STATUSLEN - strlen(status_buf));
        strncat(status_buf, ")", MAX_STATUSLEN - strlen(status_buf));
    } else {
        strcpy(status_buf, "");
    }

    status_msg(status_buf);
}
示例#16
0
/*
** handle_hsc_exec
**
** exec a sub file
*/
BOOL handle_hsc_exec( INFILE *inpf, HSCTAG *tag )
{
    STRPTR cmd = get_vartext( tag->attr, "COMMAND" );

    if ( cmd ) {

        int     result;
        EXPSTR *msg = init_estr( 0 );

        if ( msg
             && app_estr( msg, "execute: " )
             && app_estr( msg, cmd ) )
        {

            /* status message */
            status_msg( estr2str( msg ) );
            if ( verbose )
                status_lf();

            /* call command */
            result = system( cmd );

            /* check for non-zero-result */
            if ( result ) {

                 message( MSG_SYSTEM_RETURN, inpf );
                 errstr( "Calling external command returned " );
                 errstr( long2str( (LONG) result ) );
                 errlf();

            }

        } else
            err_mem( inpf );

        del_estr( msg );

    }

    return (TRUE);
}
示例#17
0
void loop() {

    // Make sure we don't update the map tile on screen when we don't need to!
    uint8_t update_display_window = 0;

    if ( first_time ) {
        first_time = 0;
        update_display_window = 1;
        }

    // Joystick displacement.
    int16_t dx = 0;
    int16_t dy = 0;
    uint8_t select_button_event = 0;

    // If the map has been zoomed in or out we need to do a redraw,
    // and will center the display window about the cursor.
    // So a zoom in-out will re-center over a mis-positioned cursor!
    
    // if the map changed as a result of a zoom button press
    if (shared_new_map_num != current_map_num) {
        #ifdef DEBUG_SCROLLING
            Serial.print("Zoom from ");
            Serial.print(current_map_num);
            Serial.print(" x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
        #endif

        // change the map and figure out the position of the cursor on
        // the new map.
        set_zoom();

        // center the display window around the cursor 
        move_window_to(
            cursor_map_x - display_window_width/2, 
            cursor_map_y - display_window_height/2);

        #ifdef DEBUG_SCROLLING
            Serial.print(" to ");
            Serial.print(current_map_num);
            Serial.print(" x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
            Serial.println();
        #endif

        // Changed the zoom level, so we want to redraw the window
        update_display_window = 1;
    }


    // Now, see if the joystick has moved, in which case we want to
    // also want to move the visible cursor on the screen.

    // Process joystick input.
    select_button_event = process_joystick(&dx, &dy);

    // the joystick routine filters out small changes, so anything non-0
    // is a real movement
    if ( abs(dx) > 0 || abs(dy) > 0 ) {
        // redraw the path if the cursor moves: (brute force yay)
        // comment out if you find it runs too slowly, and live with the
        // cursor erasing the path
        if ( path_length > 0 ) {
	  draw_path(path_length, path, current_map_num);
        }
        // Is the cursor getting near the edge of the screen?  If so
        // then scroll the map over by re-centering the window.

        uint16_t new_screen_map_x = screen_map_x;
        uint16_t new_screen_map_y = screen_map_y;
        uint8_t need_to_move = 0;

        uint16_t cursor_screen_x;
        uint16_t cursor_screen_y;
        if ( get_cursor_screen_x_y(&cursor_screen_x, &cursor_screen_y) ) {
            // if the cursor is visible, then adjust the display to 
            // to scroll if near the edge.

            if ( cursor_screen_x < screen_left_margin ) {
                new_screen_map_x = screen_map_x - screen_scroll_delta;
		move_cursor_by(3, 0);
                need_to_move = 1;
                }
            else if ( cursor_screen_x > screen_right_margin ) {
                new_screen_map_x = screen_map_x + screen_scroll_delta;
		move_cursor_by(-3, 0);
                need_to_move = 1;
            }

            if ( cursor_screen_y < screen_top_margin ) {
                new_screen_map_y = screen_map_y - screen_scroll_delta;
		move_cursor_by(0, 3);
                need_to_move = 1;
                }
            else if ( cursor_screen_y > screen_bottom_margin ) {
                new_screen_map_y = screen_map_y + screen_scroll_delta;
		move_cursor_by(0, -3);
                need_to_move = 1;
            }

            if ( need_to_move ) {
                // move the display window, leaving cursor at same lat-lon
	        move_window_to(new_screen_map_x, new_screen_map_y);
		
                update_display_window = 1;
                } 
            else {
                // erase old cursor, move, and draw new one, no need to 
                // redraw the underlying map tile
                erase_cursor();
                move_cursor_by(dx, dy);
                draw_cursor();
                }
            }

    }

    // at this point the screen is updated, with a new tile window and
    // cursor position if necessary

    // will only be down once, then waits for a min time before allowing
    // pres again.
    if (select_button_event) {
        // Button was pressed, we are selecting a point!
        #ifdef DEBUG_PATH
            Serial.print("x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
            Serial.println();
        #endif

        // which press is this, the start or the stop selection?

        // If we are making a request to find a shortest path, we will send out
        // the request on the serial port and then wait for a response from the
        // server.  While this is happening, the client user interface is
        // suspended.

        // if the stop point, then we send out the server request and wait.
        if ( request_state == 0 ) {
            // collect the start point
            start_lat = cursor_lat;
            start_lon = cursor_lon;
            request_state = 1;
            }
        else if ( request_state == 1) {
            // collect the stop point
            stop_lat = cursor_lat;
            stop_lon = cursor_lon;
            request_state = 0;

            // send out the start and stop coordinates to the server
            Serial.print(start_lat);
            Serial.print(" "); 
            Serial.print(start_lon);
            Serial.print(" "); 
            Serial.print(stop_lat);
            Serial.print(" "); 
            Serial.print(stop_lon);
            Serial.println();

            // free any existing path
            if ( path_length > 0 ) {
                free(path);
                }

            // read the path from the serial port
            status_msg("WAITING");
            if ( read_path(&path_length, &path) ) {
                #ifdef DEBUG_PATH
                    uint8_t is_visible;
                    for (uint16_t i=0; i < path_length; i++) {
                        is_visible = is_coord_visible(path[i]);
                        Serial.print(i);
                        Serial.print(": ");
                        Serial.print(path[i].lat);
                        Serial.print(",");
                        Serial.print(path[i].lon);
                        Serial.print(is_visible ? "V": "");
                        Serial.println();
                        }
                #endif
                update_display_window = 1;
                }
            else {
                // should display this error on the screen
                Serial.print("Path read error, code ");
                Serial.println(path_errno);
                if ( path_errno == 1 ) {
                    status_msg("Path too long");
                    delay(5000);
                    }
                    
                }

            }
        } // end of select_button_event processing

    // do we have to redraw the map tile?  
    if (update_display_window) {
        #ifdef DEBUG_SCROLLING
            Serial.println("Screen update");
            Serial.print(current_map_num);
            Serial.print(" ");
            Serial.print(cursor_lon);
            Serial.print(" ");
            Serial.print(cursor_lat);
            Serial.println();
        #endif

	    
        draw_map_screen();
        draw_cursor();

        // Need to redraw any other things that are on the screen
        if ( path_length > 0 ) {
	  draw_path(path_length, path, current_map_num);
            }

        // force a redisplay of status message
        clear_status_msg();
        }

    // always update the status message area if message changes
    // Indicate which point we are waiting for
    if ( request_state == 0 ) {
        status_msg("FROM?");
        }
    else {
        status_msg("TO?");
        }
    }
示例#18
0
文件: player.c 项目: Manishearth/moc
/* Decoder loop for already opened and probably running for some time decoder.
 * next_file will be precached at eof. */
static void decode_loop (const struct decoder *f, void *decoder_data,
		const char *next_file, struct out_buf *out_buf,
		struct sound_params *sound_params, struct md5_data *md5,
		const float already_decoded_sec)
{
	bool eof = false;
	bool stopped = false;
	char buf[PCM_BUF_SIZE];
	int decoded = 0;
	struct sound_params new_sound_params;
	bool sound_params_change = false;
	float decode_time = already_decoded_sec; /* the position of the decoder
						    (in seconds) */

	out_buf_set_free_callback (out_buf, buf_free_callback);

	LOCK (curr_tags_mut);
	curr_tags = tags_new ();
	UNLOCK (curr_tags_mut);

	if (f->get_stream) {
		LOCK (decoder_stream_mut);
		decoder_stream = f->get_stream (decoder_data);
		UNLOCK (decoder_stream_mut);
	}
	else
		logit ("No get_stream() function");

	status_msg ("Playing...");

	while (1) {
		debug ("loop...");

		LOCK (request_cond_mutex);
		if (!eof && !decoded) {
			struct decoder_error err;

			UNLOCK (request_cond_mutex);

			if (decoder_stream && out_buf_get_fill(out_buf)
					< PREBUFFER_THRESHOLD) {
				prebuffering = 1;
				io_prebuffer (decoder_stream,
						options_get_int("Prebuffering")
						* 1024);
				prebuffering = 0;
				status_msg ("Playing...");
			}

			decoded = f->decode (decoder_data, buf, sizeof(buf),
					&new_sound_params);

			if (decoded)
				decode_time += decoded / (float)(sfmt_Bps(
							new_sound_params.fmt) *
						new_sound_params.rate *
						new_sound_params.channels);

			f->get_error (decoder_data, &err);
			if (err.type != ERROR_OK) {
				md5->okay = false;
				if (err.type != ERROR_STREAM
						|| options_get_int(
							"ShowStreamErrors"))
					error ("%s", err.err);
				decoder_error_clear (&err);
			}

			if (!decoded) {
				eof = true;
				logit ("EOF from decoder");
			}
			else {
				debug ("decoded %d bytes", decoded);
				if (!sound_params_eq(new_sound_params, *sound_params))
					sound_params_change = true;

				bitrate_list_add (&bitrate_list, decode_time,
						f->get_bitrate(decoder_data));
				update_tags (f, decoder_data, decoder_stream);
			}
		}

		/* Wait, if there is no space in the buffer to put the decoded
		 * data or EOF occurred and there is something in the buffer. */
		else if (decoded > out_buf_get_free(out_buf)
					|| (eof && out_buf_get_fill(out_buf))) {
			debug ("waiting...");
			if (eof && !precache.file && next_file
					&& file_type(next_file) == F_SOUND
					&& options_get_int("Precache")
					&& options_get_bool("AutoNext"))
				start_precache (&precache, next_file);
			pthread_cond_wait (&request_cond, &request_cond_mutex);
			UNLOCK (request_cond_mutex);
		}
		else
			UNLOCK (request_cond_mutex);

		/* When clearing request, we must make sure, that another
		 * request will not arrive at the moment, so we check if
		 * the request has changed. */
		if (request == REQ_STOP) {
			logit ("stop");
			stopped = true;
			md5->okay = false;
			out_buf_stop (out_buf);

			LOCK (request_cond_mutex);
			if (request == REQ_STOP)
				request = REQ_NOTHING;
			UNLOCK (request_cond_mutex);

			break;
		}
		else if (request == REQ_SEEK) {
			int decoder_seek;

			logit ("seeking");
			md5->okay = false;
			req_seek = MAX(0, req_seek);
			if ((decoder_seek = f->seek(decoder_data, req_seek))
					== -1)
				logit ("error when seeking");
			else {
				out_buf_stop (out_buf);
				out_buf_reset (out_buf);
				out_buf_time_set (out_buf, decoder_seek);
				bitrate_list_empty (&bitrate_list);
				decode_time = decoder_seek;
				eof = false;
				decoded = 0;
			}

			LOCK (request_cond_mutex);
			if (request == REQ_SEEK)
				request = REQ_NOTHING;
			UNLOCK (request_cond_mutex);

		}
		else if (!eof && decoded <= out_buf_get_free(out_buf)
				&& !sound_params_change) {
			debug ("putting into the buffer %d bytes", decoded);
#if !defined(NDEBUG) && defined(DEBUG)
			if (md5->okay) {
				md5->len += decoded;
				md5_process_bytes (buf, decoded, &md5->ctx);
			}
#endif
			audio_send_buf (buf, decoded);
			decoded = 0;
		}
		else if (!eof && sound_params_change
				&& out_buf_get_fill(out_buf) == 0) {
			logit ("Sound parameters have changed.");
			*sound_params = new_sound_params;
			sound_params_change = false;
			set_info_channels (sound_params->channels);
			set_info_rate (sound_params->rate / 1000);
			out_buf_wait (out_buf);
			if (!audio_open(sound_params)) {
				md5->okay = false;
				break;
			}
		}
		else if (eof && out_buf_get_fill(out_buf) == 0) {
			logit ("played everything");
			break;
		}
	}

	status_msg ("");

	LOCK (decoder_stream_mut);
	decoder_stream = NULL;
	f->close (decoder_data);
	UNLOCK (decoder_stream_mut);

	bitrate_list_destroy (&bitrate_list);

	LOCK (curr_tags_mut);
	if (curr_tags) {
		tags_free (curr_tags);
		curr_tags = NULL;
	}
	UNLOCK (curr_tags_mut);

	out_buf_wait (out_buf);

	if (precache.ok && (stopped || !options_get_bool ("AutoNext"))) {
		precache_wait (&precache);
		precache.f->close (precache.decoder_data);
		precache_reset (&precache);
	}
}
示例#19
0
文件: player.c 项目: Manishearth/moc
/* Play a file (disk file) using the given decoder. next_file is precached. */
static void play_file (const char *file, const struct decoder *f,
		const char *next_file, struct out_buf *out_buf)
{
	void *decoder_data;
	struct sound_params sound_params = { 0, 0, 0 };
	float already_decoded_time;
	struct md5_data md5;

#if !defined(NDEBUG) && defined(DEBUG)
	md5.okay = true;
	md5.len = 0;
	md5_init_ctx (&md5.ctx);
#endif

	out_buf_reset (out_buf);

	precache_wait (&precache);

	if (precache.ok && strcmp(precache.file, file)) {
		logit ("The precached file is not the file we want.");
		precache.f->close (precache.decoder_data);
		precache_reset (&precache);
	}

	if (precache.ok && !strcmp(precache.file, file)) {
		struct decoder_error err;

		logit ("Using precached file");

		assert (f == precache.f);

		sound_params = precache.sound_params;
		decoder_data = precache.decoder_data;
		set_info_channels (sound_params.channels);
		set_info_rate (sound_params.rate / 1000);

		if (!audio_open(&sound_params)) {
			md5.okay = false;
			precache.f->close (precache.decoder_data);
			precache_reset (&precache);
			return;
		}

#if !defined(NDEBUG) && defined(DEBUG)
		md5.len += precache.buf_fill;
		md5_process_bytes (precache.buf, precache.buf_fill, &md5.ctx);
#endif

		audio_send_buf (precache.buf, precache.buf_fill);

		precache.f->get_error (precache.decoder_data, &err);
		if (err.type != ERROR_OK) {
			md5.okay = false;
			if (err.type != ERROR_STREAM
					|| options_get_int(
						"ShowStreamErrors"))
				error ("%s", err.err);
			decoder_error_clear (&err);
		}

		already_decoded_time = precache.decoded_time;

		if(f->get_avg_bitrate)
			set_info_avg_bitrate (f->get_avg_bitrate(decoder_data));
		else
			set_info_avg_bitrate (0);

		bitrate_list_init (&bitrate_list);
		bitrate_list.head = precache.bitrate_list.head;
		bitrate_list.tail = precache.bitrate_list.tail;

		/* don't free list elements when reseting precache */
		precache.bitrate_list.head = NULL;
		precache.bitrate_list.tail = NULL;
	}
	else {
		struct decoder_error err;

		status_msg ("Opening...");
		decoder_data = f->open(file);
		f->get_error (decoder_data, &err);
		if (err.type != ERROR_OK) {
			f->close (decoder_data);
			status_msg ("");
			error ("%s", err.err);
			decoder_error_clear (&err);
			logit ("Can't open file, exiting");
			return;
		}

		already_decoded_time = 0.0;
		if(f->get_avg_bitrate)
			set_info_avg_bitrate (f->get_avg_bitrate(decoder_data));
		bitrate_list_init (&bitrate_list);
	}

	audio_plist_set_time (file, f->get_duration(decoder_data));
	audio_state_started_playing ();
	precache_reset (&precache);

	decode_loop (f, decoder_data, next_file, out_buf, &sound_params,
			&md5, already_decoded_time);

#if !defined(NDEBUG) && defined(DEBUG)
	if (md5.okay) {
		uint8_t buf[MD5_DIGEST_SIZE];

		md5_finish_ctx (&md5.ctx, buf);
		log_md5_sum (file, sound_params, f, buf, md5.len);
	}
#endif
}
示例#20
0
文件: AIM.cpp 项目: Barrett17/Caya
status_t
AIMProtocol::Process(BMessage* msg)
{
	switch (msg->what) {
		case IM_MESSAGE: {
			int32 im_what = 0;
 
			msg->FindInt32("im_what", &im_what);

			switch (im_what) {
				case IM_SET_OWN_STATUS: {
					int32 status = msg->FindInt32("status");

					BString status_msg("");
					msg->FindString("message", &status_msg);
					char* smsg = strdup(status_msg.String());

					switch (status) {
						case CAYA_ONLINE:
							if (!fOnline)
								A_LogOn();
							else
								imcomm_set_unaway(fIMCommHandle);
							break;
						case CAYA_AWAY:
							imcomm_set_away(fIMCommHandle, smsg);
							break;
						case CAYA_CUSTOM_STATUS:
							//imcomm_set_away(fIMCommHandle, smsg);
							//UnsupportedOperation(); ?
							break;
						case CAYA_DO_NOT_DISTURB:
							imcomm_set_away(fIMCommHandle, smsg);
							//UnsupportedOperation(); ?
							break;
						case CAYA_OFFLINE:
							LogOff();
							break;
						default:
							break;
					}

					free(smsg);

					BMessage msg(IM_MESSAGE);
					msg.AddInt32("im_what", IM_STATUS_SET);
					msg.AddString("protocol", kProtocolSignature);
					msg.AddInt32("status", status);
					gServerMsgr->SendMessage(&msg);
					break;
				}
				case IM_SET_NICKNAME:
					UnsupportedOperation();
					break;
				case IM_SEND_MESSAGE: {
					const char* buddy = msg->FindString("id");
					const char* sms = msg->FindString("body");
					imcomm_im_send_message(fIMCommHandle, buddy, sms, 0);

					// XXX send a message to let caya know we did it
					BMessage msg(IM_MESSAGE);
					msg.AddInt32("im_what", IM_MESSAGE_SENT);
					msg.AddString("protocol", kProtocolSignature);
					msg.AddString("id", buddy);
					msg.AddString("body", sms);

					gServerMsgr->SendMessage(&msg);
					break;
				}
				case IM_REGISTER_CONTACTS: {
					const char* buddy = NULL;
					char *buddy_copy;

					for (int32 i = 0; msg->FindString("id", i, &buddy) == B_OK; i++) {
						buddy_copy = strdup(buddy);
						imcomm_im_add_buddy(fIMCommHandle, buddy_copy);
						free(buddy_copy);
					}
					break;
				}
				case IM_UNREGISTER_CONTACTS: {
					const char* buddy = NULL;

					for (int32 i = 0; msg->FindString("id", i, &buddy) == B_OK; i++)
						imcomm_im_remove_buddy(fIMCommHandle, buddy);
					break;
				}
				case IM_USER_STARTED_TYPING:
					//UnsupportedOperation();
					break;
				case IM_USER_STOPPED_TYPING:
					//UnsupportedOperation();
					break;
				case IM_GET_CONTACT_INFO:
					UnsupportedOperation();
					break;
				case IM_ASK_AUTHORIZATION:
				case IM_AUTHORIZATION_RECEIVED:
				case IM_AUTHORIZATION_REQUEST:
				case IM_AUTHORIZATION_RESPONSE:
				case IM_CONTACT_AUTHORIZED:
					UnsupportedOperation();
					break;
				case IM_SPECIAL_TO_PROTOCOL:
						UnsupportedOperation();
					break;
				default:
					return B_ERROR;
			}
			break;
		}
		default:
			// We don't handle this what code
			return B_ERROR;
	}

    return B_OK;
}
示例#21
0
void clear_status_msg() {
    status_msg("");
    }
示例#22
0
文件: ge.cpp 项目: Strongc/proview
void Ge::activate_move_vertical()
{
    graph->set_move_restriction( glow_eMoveRestriction_Vertical);
    status_msg( this, 0, 0);
}
示例#23
0
文件: ge.cpp 项目: Strongc/proview
void Ge::activate_move_reset()
{
    graph->set_move_restriction( glow_eMoveRestriction_No);
    status_msg( this, 0, 0);
}
示例#24
0
文件: ge.cpp 项目: Strongc/proview
void Ge::activate_move_horizontal()
{
    graph->set_move_restriction( glow_eMoveRestriction_Horizontal);
    status_msg( this, 0, 0);
}
示例#25
0
文件: ge.cpp 项目: Strongc/proview
void Ge::activate_scale_equal()
{
    graph->set_scale_equal( 1);
    status_msg( this, 0, 0);
}
示例#26
0
文件: ge.cpp 项目: Strongc/proview
void Ge::activate_edit_polyline()
{
    graph->set_mode( grow_eMode_EditPolyLine, false);
    status_msg( this, 0, 0);
}
示例#27
0
文件: ge.cpp 项目: Strongc/proview
void Ge::activate_scale()
{
    graph->set_mode( grow_eMode_Scale, false);
    status_msg( this, 0, 0);
}
示例#28
0
文件: ge.cpp 项目: Strongc/proview
void Ge::activate_conpoint( bool keep)
{
    graph->set_mode( grow_eMode_ConPoint, keep);
    status_msg( this, 0, 0);
}
示例#29
0
文件: MSN.cpp 项目: ModeenF/Caya
status_t
MSNP::Process(BMessage* msg)
{
//	printf("Process()\n");
//	msg->PrintToStream();

	switch (msg->what) {
		case IM_MESSAGE:
		{
			int32 im_what = 0;

			msg->FindInt32("im_what", &im_what);

			switch (im_what) {
				case IM_SET_OWN_NICKNAME:
				{
					BString nick;

					if (msg->FindString("nick", &nick) == B_OK) {
						if (fLogged) {
							fMainConnection->setFriendlyName(nick.String(), true);
							fNickname = nick.String();
						} else {
							fNickname = nick.String();
						}
					}
					break;
				}
				case IM_SET_OWN_STATUS:
				{
					int32 status = msg->FindInt32("status");
					BString status_msg("");
					msg->FindString("message", &status_msg);

					switch (status) {
						case CAYA_ONLINE:
							if (fLogged) {
								fMainConnection->setState(MSN::STATUS_AVAILABLE, fClientID);
							} else if (fSettings) {
								if (fMainConnection != NULL)
									break;

								if (fUsername == "")
									Error("Empty Username!", NULL);
								if (fPassword == "")
									Error("Empty Password!",NULL);
								
								//Progress("MSN Protocol: Login", "MSNP: Connecting...", 0.0f);
								MSN::Passport username;
								try {
									username = MSN::Passport(fUsername.c_str());
								} catch (MSN::InvalidPassport & e) {
									Error("MSN Protocol: Invalid Passport!", "Error!");
									return B_ERROR;
								}
								MSN::Callbacks* cb = dynamic_cast<MSN::Callbacks*> (this);
								fMainConnection = new MSN::NotificationServerConnection(username,
									fPassword.String(), *cb);

								resume_thread(fPollThread);
							} else {
								Error("MSN Protocol: Settings Error", NULL);
							}
							break;
						case CAYA_AWAY:
							if (fLogged)
								fMainConnection->setState(MSN::STATUS_AWAY, fClientID);
							break;
						case CAYA_CUSTOM_STATUS:

							break;
						case CAYA_DO_NOT_DISTURB:
							if (fLogged)
								fMainConnection->setState(MSN::STATUS_IDLE, fClientID);
							break;

						case CAYA_OFFLINE:
							if (fLogged) {
								fMainConnection->disconnect();
								delete fMainConnection;
								fMainConnection = NULL;
								int end = fBuddyList.CountItems();

								for (int x=0; x != end; x++) {
									MSN::Buddy contact = fBuddyList.ItemAt(x);
									if (contact.lists & MSN::LST_AL ) {
										BMessage msg(IM_MESSAGE);
										msg.AddInt32("im_what", IM_STATUS_SET);
										msg.AddString("protocol", kProtocolSignature);
										msg.AddString("id", contact.userName.c_str());
										msg.AddInt32("status", CAYA_OFFLINE);
										fServerMsgr->SendMessage(&msg);
									}
								}
								fLogged = false;
								fSettings = true;
								suspend_thread(fPollThread);
							} else {
								delete fMainConnection;
								fMainConnection = NULL;
								suspend_thread(fPollThread);
							}
							break;
					}
					break;
				}

				case IM_SEND_MESSAGE:
				{
					const char* buddy = msg->FindString("id");
					const char* sms = msg->FindString("body");

					int x, y;
					bool nouveau = true;
					int count = 0;
					count = fSwitchboardList.CountItems();
					if (count != 0) {
						for (x=0; x < count; x++) {
							if (fSwitchboardList.ItemAt(x)->first == buddy) {
								if (fSwitchboardList.ItemAt(x)->second->isConnected()) {
									nouveau = false;
									y = x;
								} else {
									delete fSwitchboardList.ItemAt(x)->second;
									fSwitchboardList.RemoveItemAt(x);
								}
								break;
							}
						}
					}

					if (nouveau) {
						MSNContainer* container = new MSNContainer(string(sms), string(buddy));
						fMainConnection->requestSwitchboardConnection(container);
					} else {
						MSN::SwitchboardServerConnection* conn = fSwitchboardList.ItemAt(y)->second;
						if (conn != NULL && conn->isConnected()) {
							conn->sendTypingNotification();
							conn->sendMessage(string(sms));
						}

						BMessage msg(IM_MESSAGE);
						msg.AddInt32("im_what", IM_MESSAGE_SENT);
						msg.AddString("protocol", kProtocolSignature);
						msg.AddString("id", buddy);
						msg.AddString("body", sms);
						fServerMsgr->SendMessage(&msg);
					}
					break;
				}
				case IM_REGISTER_CONTACTS:
				{

					break;
				}
				case IM_UNREGISTER_CONTACTS:
				{

					break;
				}
				case IM_USER_STARTED_TYPING:
				{
					const char* id = msg->FindString("id");

					int x;
					int count = 0;
					count = fSwitchboardList.CountItems();
					if (count != 0) {
						for (x=0; x < count; x++) {
							if (fSwitchboardList.ItemAt(x)->first == id) {
								if (fSwitchboardList.ItemAt(x)->second != NULL)
									fSwitchboardList.ItemAt(x)->second->sendTypingNotification();
								break;
							}
						}
					}
					break;
				}
				case IM_USER_STOPPED_TYPING:
				{

					break;
				}
				case IM_GET_CONTACT_INFO:

					break;
				default:
					// We don't handle this im_what code
					//LOG(kProtocolName, liDebug, "Got unhandled message: %ld", im_what);
					//msg->PrintToStream();
					return B_ERROR;
			}
			break;
		}
		default:
			// We don't handle this what code
			return B_ERROR;
	}
	return B_OK;
}
示例#30
0
文件: ge.cpp 项目: Strongc/proview
void Ge::activate_annot( bool keep)
{
    graph->set_mode( grow_eMode_Annot, keep);
    status_msg( this, 0, 0);
}