Exemplo n.º 1
0
int session_end(SESSION_HANDLE session, const char* condition_value, const char* description)
{
	int result;

	if (session == NULL)
	{
		result = __LINE__;
	}
	else
	{
		SESSION_INSTANCE* session_instance = (SESSION_INSTANCE*)session;

		if ((session_instance->session_state != SESSION_STATE_UNMAPPED) &&
			(session_instance->session_state != SESSION_STATE_DISCARDING))
		{
			ERROR_HANDLE error_handle = NULL;
			result = 0;

			if (condition_value != NULL)
			{
				error_handle = error_create(condition_value);
				if (error_handle == NULL)
				{
					result = __LINE__;
				}
				else
				{
					if (error_set_description(error_handle, description) != 0)
					{
						result = __LINE__;
					}
				}
			}

			if (result == 0)
			{
				if (send_end_frame(session_instance, error_handle) != 0)
				{
					result = __LINE__;
				}
				else
				{
					session_set_state(session_instance, SESSION_STATE_DISCARDING);
					result = 0;
				}
			}

			if (error_handle != NULL)
			{
				error_destroy(error_handle);
			}
		}
		else
		{
			result = 0;
		}
	}

	return result;
}
Exemplo n.º 2
0
static void end_session_with_error(SESSION_INSTANCE* session_instance, const char* condition_value, const char* description)
{
	ERROR_HANDLE error_handle = error_create(condition_value);
	if (error_handle == NULL)
	{
		/* fatal error */
		session_set_state(session_instance, SESSION_STATE_DISCARDING);
		(void)connection_close(session_instance->connection, "amqp:internal-error", "Cannot allocate error handle to end session");
	}
	else
	{
		if ((error_set_description(error_handle, description) != 0) ||
			(send_end_frame(session_instance, error_handle) != 0))
		{
			/* fatal error */
			session_set_state(session_instance, SESSION_STATE_DISCARDING);
			(void)connection_close(session_instance->connection, "amqp:internal-error", "Cannot allocate error handle to end session");
		}
		else
		{
			session_set_state(session_instance, SESSION_STATE_DISCARDING);
		}

		error_destroy(error_handle);
	}
}
Exemplo n.º 3
0
void ms_async_process(MediaScan *s) {
  if (s->thread) {
    enum event_type type;
    void *data;

    thread_signal_read(s->thread->respipe);

    // Pull events from the thread's queue, events contain their type
    // and a data pointer (Result/Error/Progress) for that callback
    // A callback may call ms_destroy, so we check for s->thread every time through the loop
    while (s->thread != NULL && (type = thread_get_next_event(s->thread, &data))) {
      LOG_DEBUG("Got thread event, type %d @ %p\n", type, data);
      switch (type) {
        case EVENT_TYPE_RESULT:
          s->on_result(s, (MediaScanResult *)data, s->userdata);
          result_destroy((MediaScanResult *)data);
          break;

        case EVENT_TYPE_PROGRESS:
          s->on_progress(s, (MediaScanProgress *)data, s->userdata);
          progress_destroy((MediaScanProgress *)data);  // freeing a copy of progress
          break;

        case EVENT_TYPE_ERROR:
          s->on_error(s, (MediaScanError *)data, s->userdata);
          error_destroy((MediaScanError *)data);
          break;

        case EVENT_TYPE_FINISH:
          s->on_finish(s, s->userdata);
          break;
      }
    }
  }
}
Exemplo n.º 4
0
// Callback or notify about an error
void send_error(MediaScan *s, MediaScanError *e) {
  if (s->thread) {
    thread_queue_event(s->thread, EVENT_TYPE_ERROR, (void *)e);
  }
  else {
    // Call error callback directly
    s->on_error(s, e, s->userdata);
    error_destroy(e);
  }
}
Exemplo n.º 5
0
void
result_destroy(MediaScanResult *r)
{
  if (r->error)
    error_destroy(r->error);
  
  switch (r->type) {
    case TYPE_VIDEO:
      if (r->type_data.video)
        video_destroy((MediaScanVideo *)r->type_data.video);
      break;
    
    // XXX other type_data types
    
    default:
      break;
  }
    
  LOG_MEM("destroy MediaScanResult @ %p\n", r);
  free(r);
}
Exemplo n.º 6
0
void ftdi_device_destroy(ftdi_device_t* dev) {
  ftdi_deinit(dev->libftdi_context);
  ftdi_free(dev->libftdi_context);
  
  error_destroy(&dev->error);
}