Пример #1
0
bool
TCPSocketChild::RecvCallback(const nsString& aType,
                             const CallbackData& aData,
                             const uint32_t& aReadyState)
{
  mSocket->UpdateReadyState(aReadyState);

  if (aData.type() == CallbackData::Tvoid_t) {
    mSocket->FireEvent(aType);

  } else if (aData.type() == CallbackData::TTCPError) {
    const TCPError& err(aData.get_TCPError());
    mSocket->FireErrorEvent(err.name(), err.message());

  } else if (aData.type() == CallbackData::TSendableData) {
    const SendableData& data = aData.get_SendableData();

    if (data.type() == SendableData::TArrayOfuint8_t) {
      mSocket->FireDataArrayEvent(aType, data.get_ArrayOfuint8_t());
    } else if (data.type() == SendableData::TnsCString) {
      mSocket->FireDataStringEvent(aType, data.get_nsCString());
    } else {
      MOZ_CRASH("Invalid callback data type!");
    }
  } else {
    MOZ_CRASH("Invalid callback type!");
  }
  return true;
}
Пример #2
0
bool
SBBreakpoint::PrivateBreakpointHitCallback(void *baton,
                                           StoppointCallbackContext *ctx,
                                           lldb::user_id_t break_id,
                                           lldb::user_id_t break_loc_id)
{
    ExecutionContext exe_ctx (ctx->exe_ctx_ref);
    BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
    if (baton && bp_sp)
    {
        CallbackData *data = (CallbackData *)baton;
        lldb_private::Breakpoint *bp = bp_sp.get();
        if (bp && data->callback)
        {
            Process *process = exe_ctx.GetProcessPtr();
            if (process)
            {
                SBProcess sb_process (process->shared_from_this());
                SBThread sb_thread;
                SBBreakpointLocation sb_location;
                assert (bp_sp);
                sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
                Thread *thread = exe_ctx.GetThreadPtr();
                if (thread)
                    sb_thread.SetThread(thread->shared_from_this());

                return data->callback (data->callback_baton, 
                                          sb_process, 
                                          sb_thread, 
                                          sb_location);
            }
        }
    }
    return true;    // Return true if we should stop at this breakpoint
}
gboolean gtk_callback(void* callback) {
   CallbackData* cdata = (CallbackData*)callback;
   cdata->func(cdata->data);
   delete cdata;
   
   return false;
}
Пример #4
0
/******************************************************************************
* void Event::setCallback
******************************************************************************/
void Event::setCallback(cl_int command_exec_callback_type,
                        event_callback callback,
                        void *user_data)
{
    CallbackData data;
    bool call_now = false;

    data.callback = callback;
    data.user_data = user_data;

    pthread_mutex_lock(&p_state_mutex);

    /* if event already in or past command_exec_callback_type, call callback */
    /* cl.h: CL_COMPLETE 0, CL_RUNNING 1, CL_SUBMITTED 2, CL_QUEUED 3 */
    if (command_exec_callback_type >= p_status)
        call_now = true;
    else
        p_callbacks.insert(std::pair<Status, CallbackData>(
                                   (Status)command_exec_callback_type, data) );

    pthread_mutex_unlock(&p_state_mutex);

    if (call_now)
        data.callback(desc(this), p_status, data.user_data);
}
Пример #5
0
// static
void AudioOutput::CallbackWrapper(int aEvent, void* aCookie, void* aInfo)
{
  CallbackData* data = (CallbackData*) aCookie;
  data->Lock();
  AudioOutput* me = data->GetOutput();
  AudioTrack::Buffer* buffer = (AudioTrack::Buffer*) aInfo;
  if (!me) {
    // no output set, likely because the track was scheduled to be reused
    // by another player, but the format turned out to be incompatible.
    data->Unlock();
    if (buffer) {
      buffer->size = 0;
    }
    return;
  }

  switch(aEvent) {

    case AudioTrack::EVENT_MORE_DATA: {

      size_t actualSize = (*me->mCallback)(me, buffer->raw, buffer->size,
          me->mCallbackCookie, CB_EVENT_FILL_BUFFER);

      if (actualSize == 0 && buffer->size > 0) {
        // We've reached EOS but the audio track is not stopped yet,
        // keep playing silence.
        memset(buffer->raw, 0, buffer->size);
        actualSize = buffer->size;
      }

      buffer->size = actualSize;
    } break;

    case AudioTrack::EVENT_STREAM_END:
      AUDIO_OFFLOAD_LOG(PR_LOG_DEBUG, ("Callback wrapper: EVENT_STREAM_END"));
      (*me->mCallback)(me, nullptr /* buffer */, 0 /* size */,
          me->mCallbackCookie, CB_EVENT_STREAM_END);
      break;

    case AudioTrack::EVENT_NEW_IAUDIOTRACK :
      AUDIO_OFFLOAD_LOG(PR_LOG_DEBUG, ("Callback wrapper: EVENT_TEAR_DOWN"));
      (*me->mCallback)(me,  nullptr /* buffer */, 0 /* size */,
          me->mCallbackCookie, CB_EVENT_TEAR_DOWN);
      break;

    default:
      AUDIO_OFFLOAD_LOG(PR_LOG_DEBUG, ("received unknown event type: %d in"
          " Callback wrapper!", aEvent));
      break;
  }

  data->Unlock();
}
static gboolean
emit_select_callback_in_idle (gpointer user_data)
{
  CallbackData *data = user_data;

  if (!data->aborted)
    data->callback (&data->rectangle, data->callback_data);
  else
    data->callback (NULL, data->callback_data);

  g_slice_free (CallbackData, data);

  return FALSE;
}
Пример #7
0
static gboolean
password_requester (GMimeCryptoContext *ctx, const char *user_id,
		    const char* prompt_ctx, gboolean reprompt,
		    GMimeStream *response, GError **err)
{
	CallbackData *cbdata;
	gchar *password;
	ssize_t written;

	cbdata = g_object_get_data (G_OBJECT(ctx), CALLBACK_DATA);
	if (!cbdata || !cbdata->pw_func)
		return FALSE;

	password = cbdata->pw_func (user_id, prompt_ctx, reprompt,
				    cbdata->user_data);
	if (!password) {
		mu_util_g_set_error (err, MU_ERROR_CRYPTO,
				     "failed to get password");
		return FALSE;
	}

	written = g_mime_stream_write_string (response, password);
	if (written != -1)
		written = g_mime_stream_write_string (response, "\n");
	if (written == -1)
		mu_util_g_set_error (err, MU_ERROR_CRYPTO,
				     "writing password to mime stream failed");

	/* it seems that GMime tries to flush the fd; however, this
	 * does not work for pipes/sockets, causing getting a password
	 * to fail.
	 *
	 * I have reported this, and it has been fixed now:
	 *
	 * http://git.gnome.org/browse/gmime/commit/
	 *      ?id=bda4834d3d9a1fbefb6d97edfef2bc1da9357f58
	 *
	 * however, it may take a while before everybody has this
	 * version of GMime (ie. version > 2.6.10)
	 *
	 */

	memset (password, 0, strlen(password));
	g_free (password);

	return written != -1 ? TRUE : FALSE;
}
bool
TCPSocketChild::RecvCallback(const nsString& aType,
                             const CallbackData& aData,
                             const nsString& aReadyState,
                             const uint32_t& aBuffered)
{
  if (NS_FAILED(mSocket->UpdateReadyStateAndBuffered(aReadyState, aBuffered)))
    NS_ERROR("Shouldn't fail!");

  nsresult rv = NS_ERROR_FAILURE;
  if (aData.type() == CallbackData::Tvoid_t) {
    rv = mSocket->CallListenerVoid(aType);

  } else if (aData.type() == CallbackData::TTCPError) {
    const TCPError& err(aData.get_TCPError());
    rv = mSocket->CallListenerError(aType, err.name());

  } else if (aData.type() == CallbackData::TSendableData) {
    const SendableData& data = aData.get_SendableData();

    if (data.type() == SendableData::TArrayOfuint8_t) {
      JSContext* cx = nsContentUtils::GetSafeJSContext();
      JS::Rooted<JS::Value> val(cx);
      JS::Rooted<JSObject*> window(cx, mWindowObj);
      bool ok = IPC::DeserializeArrayBuffer(window, data.get_ArrayOfuint8_t(), &val);
      NS_ENSURE_TRUE(ok, true);
      rv = mSocket->CallListenerArrayBuffer(aType, val);

    } else if (data.type() == SendableData::TnsString) {
      rv = mSocket->CallListenerData(aType, data.get_nsString());

    } else {
      MOZ_CRASH("Invalid callback data type!");
    }

  } else {
    MOZ_CRASH("Invalid callback type!");
  }
  NS_ENSURE_SUCCESS(rv, true);
  return true;
}
Пример #9
0
static gboolean
password_requester (GMimeCryptoContext *ctx, const char *user_id,
		    const char* prompt_ctx, gboolean reprompt,
		    GMimeStream *response, GError **err)
{
	CallbackData *cbdata;
	gchar *password;
	ssize_t written;

	cbdata = g_object_get_data (G_OBJECT(ctx), CALLBACK_DATA);
	if (!cbdata || !cbdata->pw_func)
		return FALSE;

	password = cbdata->pw_func (user_id, prompt_ctx, reprompt,
				    cbdata->user_data);
	if (!password) {
		mu_util_g_set_error (err, MU_ERROR_CRYPTO,
				     "failed to get password");
		return FALSE;
	}

	written = g_mime_stream_write_string (response, password);
	if (written != -1)
		written = g_mime_stream_write_string (response, "\n");
	if (written == -1)
		mu_util_g_set_error (err, MU_ERROR_CRYPTO,
			             "writing password to mime stream failed");

	if (g_mime_stream_flush (response) != 0)
		g_printerr ("error flushing stream\n");

	memset (password, 0, strlen(password));
	g_free (password);

	return written != -1 ? TRUE : FALSE;
}
void cMetainfoMenu::Display(void)
{
  cOsdMenu::Display();

  CallbackData data;

#ifdef HAVE_LIBEXTRACTOR
#  if EXTRACTOR_VERSION >= 0x00060000

  EXTRACTOR_PluginList * plugins;

  plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY);
  EXTRACTOR_extract(plugins, m_Filename, NULL, 0, (EXTRACTOR_MetaDataProcessor)&extractor_callback_metainfo, &data);
  EXTRACTOR_plugin_remove_all(plugins); /* unload plugins */

#  else // EXTRACTOR_VERSION >= 0x00060000

  EXTRACTOR_ExtractorList * plugins;
  EXTRACTOR_KeywordList   * md_list;

  plugins = EXTRACTOR_loadDefaultLibraries();
  md_list = EXTRACTOR_getKeywords(plugins, m_Filename);
  md_list = EXTRACTOR_removeEmptyKeywords (md_list);
  md_list = EXTRACTOR_removeDuplicateKeywords(md_list, 0);
  md_list = EXTRACTOR_removeKeywordsOfType(md_list, EXTRACTOR_THUMBNAILS);

  while(md_list) {
    const char *key = EXTRACTOR_getKeywordTypeAsString(md_list->keywordType);
    if (key)
      data.Append(key, md_list->keyword);
    md_list = md_list->next;
  }

  EXTRACTOR_freeKeywords(md_list);
  EXTRACTOR_removeAll(plugins); /* unload plugins */

#  endif // EXTRACTOR_VERSION >= 0x00060000
#else // HAVE_LIBEXTRACTOR

  cString cmd;
  if(xc.IsPlaylistFile(m_Filename))
    cmd = cString::sprintf("file -b '%s'; cat '%s'", *m_Filename, *m_Filename);
  else if(xc.IsAudioFile(m_Filename))
    cmd = cString::sprintf("mp3info -x '%s' ; file -b '%s'", *m_Filename, *m_Filename);
  else if(xc.IsVideoFile(m_Filename))
    cmd = cString::sprintf("file -b '%s'; midentify '%s'", *m_Filename, *m_Filename);
  else if(xc.IsImageFile(m_Filename))
    cmd = cString::sprintf("file -b '%s'; identify '%s'", *m_Filename, *m_Filename);
  else
    cmd = cString::sprintf("file -b '%s'", *m_Filename);

  cPipe p;
  if(p.Open(*cmd, "r")) {
    data.text_len = fread(data.text, 1, data.text_size - 1, p);
    if (data.text_len > 0) {
      data.text[data.text_len] = 0;
      strreplace(data.text, ',', '\n');
    }
  }

#endif // HAVE_LIBEXTRACTOR

  DisplayMenu()->SetText(data.text, false);
  data.text = NULL;

  cStatus::MsgOsdTextItem(cString::sprintf("%s\n%s", tr("Metainfo"), *m_Filename));
}
Пример #11
0
void CompartmentCallback(JSRuntime *rt, void *vdata, JSCompartment *compartment)
{
    CallbackData *data = (CallbackData *) vdata;
    data->n += data->mallocSizeOf(compartment);
}