コード例 #1
0
ファイル: interpreter.c プロジェクト: tho068/database-2
static void syntax_error ( char *near_str )
{
  put_msg (ERROR, "Syntax error near\n");
  put_msg (ERROR, "  ... >>>%s<<<", near_str);
  if (fgets(rest_of_line, 200, in_s))
    append_msg (ERROR, rest_of_line);
}
コード例 #2
0
ファイル: BikeComputer.c プロジェクト: darkenk/BikeComputer
void second_handler()
{
#ifdef HEART_BEAT
    PORTB ^= (1<<PB0);
#endif
    append_msg(MSG_SECOND_CHANGE, 0, 0);
}
コード例 #3
0
ファイル: schema.c プロジェクト: tho068/database-2
void put_record_info ( pmsg_level level, record r, schema_p s )
{
  field_desc_p f;
  int i = 0;
  put_msg (level, "Record: ");
  for ( f = s->first; f != NULL; f = f->next, i++)
    {
      if ( is_int_field (f) )
	append_msg (level,  "%d", *(int *)r[i] );
      else
	append_msg (level,  "%s", (char *)r[i] );
			
      if (f->next != NULL)
	append_msg (level,  " | " );
    }
  append_msg (level,  "\n" );
}
コード例 #4
0
ファイル: schema.c プロジェクト: tho068/database-2
void put_field_info ( pmsg_level level, field_desc_p f )
{
  if ( f == NULL )
    {
      put_msg (level,  "  empty field\n");
      return;
    }	
  put_msg (level, "  \"%s\", ", f->name);
  if ( is_int_field (f) )
    append_msg (level,  "int ");
  else
    append_msg (level,  "str ");
  append_msg (level, "field, len: %d, offset: %d, ", f->len, f->offset);
  if (f->next != NULL)
    append_msg (level,  ", next field: %s\n", f->next->name);
  else
    append_msg (level,  "\n");
}
コード例 #5
0
bool XBee_Message::append_msg(const GBeeRxPacket *msg) {
	XBee_Message tmp_msg(msg);
	return append_msg(tmp_msg);
}
コード例 #6
0
/**
	@brief Either send or enqueue a response to a client, optionally with a completion notice.
	@param ctx Pointer to the method context.
	@param data Pointer to the response, in the form of a jsonObject.
	@param complete Boolean: if true, we will accompany the RESULT message with a STATUS
	message indicating that the response is complete.
	@return Zero if successful, or -1 upon error.

	For an atomic method, add a copy of the response data to a cache within the method
	context, to be sent later.  In this case the @a complete parameter has no effect,
	because we'll send the STATUS message later when we send the cached results.

	If the method is not atomic, translate the message into JSON and append it to a buffer,
	flushing the buffer as needed to avoid overflow.  If @a complete is true, append
	a STATUS message (as JSON) to the buffer and flush the buffer.
*/
static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int complete ) {
	if(!(ctx && ctx->method)) return -1;

	if( ctx->method->options & OSRF_METHOD_ATOMIC ) {
		osrfLogDebug( OSRF_LOG_MARK,
			"Adding responses to stash for atomic method %s", ctx->method->name );

		// If we don't already have one, create a JSON_ARRAY to serve as a cache.
		if( ctx->responses == NULL )
			ctx->responses = jsonNewObjectType( JSON_ARRAY );

		// Add a copy of the data object to the cache.
		if ( data != NULL )
			jsonObjectPush( ctx->responses, jsonObjectClone(data) );
	} else {
		osrfLogDebug( OSRF_LOG_MARK,
			"Adding responses to stash for method %s", ctx->method->name );

		if( data ) {
			// If you want to flush the intput buffers for every output message,
			// this is the place to do it.
			//osrf_app_session_queue_wait( ctx->session, 0, NULL );

			// Create an OSRF message
			osrfMessage* msg = osrf_message_init( RESULT, ctx->request, 1 );
			osrf_message_set_status_info( msg, NULL, "OK", OSRF_STATUS_OK );
			osrf_message_set_result( msg, data );

			// Serialize the OSRF message into JSON text
			char* json = jsonObjectToJSON( osrfMessageToJSON( msg ));
			osrfMessageFree( msg );

			// If the new message would overflow the buffer, flush the output buffer first
			int len_so_far = buffer_length( ctx->session->outbuf );
			if( len_so_far && (strlen( json ) + len_so_far + 3 >= ctx->method->bufsize )) {
				if( flush_responses( ctx->session, ctx->session->outbuf ))
					return -1;
			}

			// Append the JSON text to the output buffer
			append_msg( ctx->session->outbuf, json );
			free( json );
		}

		if(complete) {
			// Create a STATUS message
			osrfMessage* status_msg = osrf_message_init( STATUS, ctx->request, 1 );
			osrf_message_set_status_info( status_msg, "osrfConnectStatus", "Request Complete",
				OSRF_STATUS_COMPLETE );

			// Serialize the STATUS message into JSON text
			char* json = jsonObjectToJSON( osrfMessageToJSON( status_msg ));
			osrfMessageFree( status_msg );

			// Add the STATUS message to the output buffer.
			// It's short, so don't worry about avoiding overflow.
			append_msg( ctx->session->outbuf, json );
			free( json );

			// Flush the output buffer, sending any accumulated messages.
			if( flush_responses( ctx->session, ctx->session->outbuf ))
				return -1;
		}
	}

	return 0;
}