예제 #1
0
gboolean
gst_droidcamsrc_dev_start (GstDroidCamSrcDev * dev, gboolean apply_settings)
{
  gboolean ret = FALSE;
  GstDroidCamSrc *src = GST_DROIDCAMSRC (GST_PAD_PARENT (dev->imgsrc->pad));

  g_rec_mutex_lock (dev->lock);

  if (dev->running) {
    GST_WARNING_OBJECT (src, "preview is already running");
    ret = TRUE;
    goto out;
  }

  GST_DEBUG_OBJECT (src, "dev start");

  if (!gst_buffer_pool_set_active (dev->pool, TRUE)) {
    GST_ERROR_OBJECT (src, "Failed to activate buffer pool");
    goto out;
  }

  if (apply_settings) {
    gst_droidcamsrc_apply_mode_settings (src, SET_ONLY);
  }

  /* now set params */
  if (!gst_droidcamsrc_dev_set_params (dev)) {
    goto out;
  }

  if (dev->use_raw_data) {
    GST_INFO_OBJECT (src, "Using raw data mode");
    droid_media_camera_set_preview_callback_flags (dev->cam,
        dev->c.CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
  } else {
    GST_INFO_OBJECT (src, "Using native buffers mode");
    droid_media_camera_set_preview_callback_flags (dev->cam,
        dev->c.CAMERA_FRAME_CALLBACK_FLAG_NOOP);
  }

  if (!droid_media_camera_start_preview (dev->cam)) {
    GST_ERROR_OBJECT (src, "error starting preview");
    goto out;
  }

  dev->running = TRUE;

  ret = TRUE;

out:
  if (ret != TRUE) {
    gst_buffer_pool_set_active (dev->pool, FALSE);
  }

  g_rec_mutex_unlock (dev->lock);
  return ret;
}
예제 #2
0
static gboolean
on_immediate_wakeup_source_ready (GoaAlarm *self)
{
  g_return_val_if_fail (self->priv->type != GOA_ALARM_TYPE_UNSCHEDULED, FALSE);

  g_rec_mutex_lock (&self->priv->lock);
  fire_or_rearm_alarm (self);
  g_rec_mutex_unlock (&self->priv->lock);
  return FALSE;
}
예제 #3
0
파일: gmodule.c 프로젝트: 183amir/glib
/**
 * g_module_close:
 * @module: a #GModule to close
 *
 * Closes a module.
 *
 * Returns: %TRUE on success
 */
gboolean
g_module_close (GModule *module)
{
  SUPPORT_OR_RETURN (FALSE);
  
  g_return_val_if_fail (module != NULL, FALSE);
  g_return_val_if_fail (module->ref_count > 0, FALSE);
  
  g_rec_mutex_lock (&g_module_global_lock);

  module->ref_count--;
  
  if (!module->ref_count && !module->is_resident && module->unload)
    {
      GModuleUnload unload;

      unload = module->unload;
      module->unload = NULL;
      unload (module);
    }

  if (!module->ref_count && !module->is_resident)
    {
      GModule *last;
      GModule *node;
      
      last = NULL;
      
      node = modules;
      while (node)
	{
	  if (node == module)
	    {
	      if (last)
		last->next = node->next;
	      else
		modules = node->next;
	      break;
	    }
	  last = node;
	  node = last->next;
	}
      module->next = NULL;
      
      _g_module_close (module->handle, FALSE);
      g_free (module->file_name);
#if defined (G_OS_WIN32) && !defined(_WIN64)
      g_free (module->cp_file_name);
#endif
      g_free (module);
    }
  
  g_rec_mutex_unlock (&g_module_global_lock);
  return g_module_error() == NULL;
}
예제 #4
0
static GstStateChangeReturn
dvb_base_bin_change_state (GstElement * element, GstStateChange transition)
{
  DvbBaseBin *dvbbasebin;
  GstStateChangeReturn ret;

  dvbbasebin = GST_DVB_BASE_BIN (element);

  switch (transition) {
    case GST_STATE_CHANGE_NULL_TO_READY:
      if (dvbbasebin->tsparse == NULL) {
        GST_ELEMENT_ERROR (dvbbasebin, CORE, MISSING_PLUGIN, (NULL),
            ("No 'tsparse' element, check your GStreamer installation."));
        return GST_STATE_CHANGE_FAILURE;
      }
      break;
    default:
      break;
  }

  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);

  switch (transition) {
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      gst_poll_set_flushing (dvbbasebin->poll, FALSE);
      g_rec_mutex_lock (&dvbbasebin->lock);
      gst_task_start (dvbbasebin->task);
      g_rec_mutex_unlock (&dvbbasebin->lock);
      break;
    case GST_STATE_CHANGE_PAUSED_TO_READY:
      gst_poll_set_flushing (dvbbasebin->poll, TRUE);
      g_rec_mutex_lock (&dvbbasebin->lock);
      gst_task_stop (dvbbasebin->task);
      g_rec_mutex_unlock (&dvbbasebin->lock);
      dvb_base_bin_reset (dvbbasebin);
      break;
    default:
      break;
  }

  return ret;
}
예제 #5
0
파일: gda-pstmt.c 프로젝트: GNOME/libgda
/**
 * gda_pstmt_get_gda_statement:
 * @pstmt: a #GdaPStmt object
 *
 * Get a pointer to the #GdaStatement which led to the creation of this prepared statement.
 * 
 * Note: if that statement has been modified since the creation of @pstmt, then this method
 * will return %NULL
 *
 * Returns: (transfer full): the #GdaStatement
 */
GdaStatement *
gda_pstmt_get_gda_statement (GdaPStmt *pstmt)
{
	g_return_val_if_fail (GDA_IS_PSTMT (pstmt), NULL);
	GdaPStmtPrivate *priv = gda_pstmt_get_instance_private (pstmt);
	g_rec_mutex_lock (& priv->mutex);
	GdaStatement *stmt;
	stmt = g_weak_ref_get (& priv->gda_stmt_ref);
	g_rec_mutex_unlock (& priv->mutex);
	return stmt;
}
예제 #6
0
gboolean
gst_droidcamsrc_dev_is_running (GstDroidCamSrcDev * dev)
{
  gboolean ret;

  g_rec_mutex_lock (dev->lock);
  ret = dev->running;
  g_rec_mutex_unlock (dev->lock);

  return ret;
}
예제 #7
0
파일: gda-pstmt.c 프로젝트: arthurnn/libgda
/**
 * gda_pstmt_get_gda_statement:
 * @pstmt: a #GdaPStmt object
 *
 * Get a pointer to the #GdaStatement which led to the creation of this prepared statement.
 * 
 * Note: if that statement has been modified since the creation of @pstmt, then this method
 * will return %NULL
 *
 * Returns: (transfer none): the #GdaStatement
 */
GdaStatement *
gda_pstmt_get_gda_statement (GdaPStmt *pstmt)
{
	g_return_val_if_fail (GDA_IS_PSTMT (pstmt), NULL);
	g_rec_mutex_lock (& pstmt->priv->mutex);
	GdaStatement *stmt;
	stmt = g_weak_ref_get (& pstmt->priv->gda_stmt_ref);
	if (stmt)
		g_object_unref (stmt);
	g_rec_mutex_unlock (& pstmt->priv->mutex);
	return stmt;
}
예제 #8
0
/**
 * mega_http_client_post:
 * @http_client: a #MegaHttpClient
 * @url: URL to make the POST to.
 * @request_length: Length of the request body.
 * @err: Error.
 *
 * Start a new POST request.
 *
 * Returns: (transfer full): IO stream you'd use to write request body and read
 * response.
 */
MegaHttpIOStream* mega_http_client_post(MegaHttpClient* http_client, const gchar* url, gint64 request_length, GError** err)
{
  GError* local_err = NULL;
  gchar* host = NULL;
  gchar* resource = NULL;
  guint16 port = 80;
  gboolean https = FALSE;
  gboolean reconnect = FALSE;

  g_return_val_if_fail(MEGA_IS_HTTP_CLIENT(http_client), NULL);
  g_return_val_if_fail(url != NULL, NULL);
  g_return_val_if_fail(err == NULL || *err == NULL, NULL);

  MegaHttpClientPrivate* priv = http_client->priv;

  // parse URL
  if (!parse_url(http_client, url, &https, &host, &port, &resource))
  {
    g_set_error(err, MEGA_HTTP_CLIENT_ERROR, MEGA_HTTP_CLIENT_ERROR_OTHER, "Invalid URL: %s", url);
    return NULL;
  }

  g_rec_mutex_lock(priv->lock);
  // check that there is a change in host or https flag
  if (priv->host == NULL || g_ascii_strcasecmp(priv->host, host) || priv->https != https || priv->port != port) 
  {
    g_free(priv->host);
    priv->host = host;
    priv->https = https;
    priv->port = port;

    // host/port/ssl changed, reconnection is necessary
    goto_state(http_client, CONN_STATE_NONE, NULL, NULL);
  }

  g_free(priv->resource);
  priv->resource = resource;

  if (!goto_state(http_client, CONN_STATE_INIT_CONNECTED, NULL, &local_err))
  {
    g_propagate_error(err, local_err);
    g_rec_mutex_unlock(priv->lock);
    return NULL;
  }

  priv->request_length = request_length;
  priv->expected_write_count = request_length;
  priv->expected_read_count = -1;
  priv->response_length = -1;

  g_rec_mutex_unlock(priv->lock);
  return mega_http_io_stream_new(http_client);
}
예제 #9
0
void
gegl_buffer_linear_close (GeglBuffer *buffer,
                          gpointer    linear)
{
  GeglTile *tile;
  tile = g_object_get_data (G_OBJECT (buffer), "linear-tile");
  if (tile)
    {
      gegl_tile_unlock (tile);
      gegl_tile_unref (tile);
      g_object_set_data (G_OBJECT (buffer), "linear-tile", NULL);
    }
  else
    {
      GList *linear_buffers;
      GList *iter;
      linear_buffers = g_object_get_data (G_OBJECT (buffer), "linear-buffers");

      for (iter = linear_buffers; iter; iter=iter->next)
        {
          BufferInfo *info = iter->data;

          if (info->buf == linear)
            {
              info->refs--;

              if (info->refs>0)
                {
                  g_print ("EEeeek! %s\n", G_STRLOC);
                return; /* there are still others holding a reference to
                         * this linear buffer
                         */
                }

              linear_buffers = g_list_remove (linear_buffers, info);
              g_object_set_data (G_OBJECT (buffer), "linear-buffers", linear_buffers);

              g_rec_mutex_unlock (&buffer->tile_storage->mutex);
              /* XXX: potential race */
              gegl_buffer_set (buffer, &info->extent, 0, info->format, info->buf, 0);

              gegl_free (info->buf);
              g_free (info);

              g_rec_mutex_lock (&buffer->tile_storage->mutex);
              break;
            }
        }
    }
  /*gegl_buffer_unlock (buffer);*/
  g_rec_mutex_unlock (&buffer->tile_storage->mutex);
  return;
}
예제 #10
0
void
gst_droidcamsrc_dev_stop_autofocus (GstDroidCamSrcDev * dev)
{
  g_rec_mutex_lock (dev->lock);

  if (dev->cam) {
    if (!droid_media_camera_cancel_auto_focus (dev->cam))
      GST_WARNING ("error stopping autofocus");
  }

  g_rec_mutex_unlock (dev->lock);
}
예제 #11
0
void
_gum_duk_interceptor_flush (GumDukInterceptor * self)
{
  gum_interceptor_begin_transaction (self->interceptor);
  g_hash_table_remove_all (self->invocation_listeners);
  g_hash_table_remove_all (self->replacement_by_address);
  gum_interceptor_end_transaction (self->interceptor);

  g_rec_mutex_unlock (&self->core->mutex);
  gum_interceptor_flush (self->interceptor);
  g_rec_mutex_lock (&self->core->mutex);
}
예제 #12
0
파일: gda-worker.c 프로젝트: zzeroo/libgda
/**
 * gda_worker_fetch_job_result: (skip)
 * @worker: a #GdaWorker object
 * @job_id: the ID of the job, as returned by gda_worker_submit_job()
 * @out_result: (allow-none): a place to store the value returned by the execution of the requested function within the worker thread, or %NULL
 * @error: (allow-none): a place to store errors, or %NULL
 *
 * Fetch the value returned by execution the @job_id job.
 *
 * Warning: if an error occurred during the
 * execution of the requested function within the worker thread, then it will show as @error, while the return value
 * of this function will be %TRUE.
 *
 * Note: if there is a result, it will be stored in @out_result, and it's up to the caller to free
 * the result, the #GdaWorker object will not do it (ownership of the result is transfered to the caller).
 *
 * Returns: %TRUE if the jobs has completed
 *
 * Since: 6.0
 */
gboolean
gda_worker_fetch_job_result (GdaWorker *worker, guint job_id, gpointer *out_result, GError **error)
{
	g_return_val_if_fail (worker, FALSE);
	if (!worker->jobs_hash) {
		g_warning ("GdaWorker has been destroyed\n");
		return FALSE;
	}

	gda_worker_ref (worker); /* increase reference count to having @worker freed while destroying job */

	if (out_result)
		*out_result = NULL;

	g_rec_mutex_lock (&worker->rmutex);
	WorkerJob *job;
	job = g_hash_table_lookup (worker->jobs_hash, &job_id);
	if (!job) {
		g_rec_mutex_unlock (& worker->rmutex);
		g_set_error (error, GDA_WORKER_ERROR, GDA_WORKER_JOB_NOT_FOUND_ERROR,
			     _("Unknown requested job %u"), job_id);
		gda_worker_unref (worker);
		return FALSE;
	}

	gboolean retval = FALSE;
	if (job->status & JOB_CANCELLED)
		g_set_error (error, GDA_WORKER_ERROR, GDA_WORKER_JOB_CANCELLED_ERROR,
			     _("Job %u has been cancelled"), job_id);
	else if (job->status & JOB_PROCESSED) {
		retval = TRUE;
		if (out_result) {
			*out_result = job->result;
			job->result = NULL;
		}
		if (job->error) {
			g_propagate_error (error, job->error);
			job->error = NULL;
		}
		g_hash_table_remove (worker->jobs_hash, &job_id);
	}
	else if (job->status & JOB_BEING_PROCESSED)
		g_set_error (error, GDA_WORKER_ERROR, GDA_WORKER_JOB_BEING_PROCESSED_ERROR,
			     _("Job %u is being processed"), job_id);
	else
		g_set_error (error, GDA_WORKER_ERROR, GDA_WORKER_JOB_QUEUED_ERROR,
			     _("Job %u has not yet been processed"), job_id);
	g_rec_mutex_unlock (&worker->rmutex);

	gda_worker_unref (worker);

	return retval;
}
예제 #13
0
static void
lbc_lock(void)
{
    static gboolean initialized = FALSE;

    g_rec_mutex_lock(&lbc_mutex);
    if (!initialized) {
        lbc_init(&lbc_conf, "config", ".gnome2");
        lbc_init(&lbc_conf_priv, "config-private", ".gnome2_private");
        initialized = TRUE;
    }
}
예제 #14
0
static void
start_worker (GdaConnection *cnc, WebConnectionData *cdata)
{
	ThreadData *thdata;

	thdata = g_new0 (ThreadData, 1); /* freed by sub thread */
	thdata->cnc = cnc;
	thdata->cdata = cdata;

	/* set cdata->worker_running to TRUE to avoid having to add a delay */
	g_rec_mutex_lock (& (cdata->mutex));
	cdata->worker_running = TRUE;
	g_rec_mutex_unlock (& (cdata->mutex));

	if (! g_thread_new ("web-worker", (GThreadFunc) start_worker_in_sub_thread,
			    thdata)) {
		g_free (thdata);
		gda_connection_add_event_string (cnc, _("Can't start new thread"));
		return;
	}
	
	gint nb_retries;
	for (nb_retries = 0; nb_retries < 10; nb_retries++) {
		gboolean wait_over;
		g_rec_mutex_lock (& (cdata->mutex));
		wait_over = !cdata->worker_running || cdata->session_id;
		g_rec_mutex_unlock (& (cdata->mutex));
		if (wait_over)
			break;
		else
			g_usleep (200000);
	}

	g_rec_mutex_lock (& (cdata->mutex));
	if (!cdata->session_id) {
		/* there was an error */
		cdata->worker_running = FALSE;
	}
	g_rec_mutex_unlock (& (cdata->mutex));
}
예제 #15
0
파일: gda-worker.c 프로젝트: zzeroo/libgda
/**
 * gda_worker_ref: (skip)
 * @worker: a #GdaWorker
 *
 * Increases @worker's reference count.
 *
 * Returns: (transfer full): @worker
 *
 * Since: 6.0
 */
GdaWorker *
gda_worker_ref (GdaWorker *worker)
{
	g_return_val_if_fail (worker, NULL);
	g_rec_mutex_lock (& worker->rmutex);
	worker->ref_count ++;
#ifdef DEBUG_NOTIFICATION
	g_print ("[W] GdaWorker %p reference increased to %u\n", worker, worker->ref_count);
#endif
	g_rec_mutex_unlock (& worker->rmutex);

	return worker;
}
예제 #16
0
/**
 * g_static_rec_mutex_lock_full:
 * @mutex: a #GStaticRecMutex to lock.
 * @depth: number of times this mutex has to be unlocked to be
 *         completely unlocked.
 *
 * Works like calling g_static_rec_mutex_lock() for @mutex @depth times.
 *
 * Deprecated: 2.32: Use g_rec_mutex_lock()
 */
void
g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
                              guint            depth)
{
  GRecMutex *rm;

  rm = g_static_rec_mutex_get_rec_mutex_impl (mutex);
  while (depth--)
    {
      g_rec_mutex_lock (rm);
      mutex->depth++;
    }
}
예제 #17
0
gboolean
gst_droidcamsrc_dev_init (GstDroidCamSrcDev * dev)
{
  GstStructure *config;

  GST_DEBUG ("dev init");

  g_rec_mutex_lock (dev->lock);

  /* first the buffer pool */
  config = gst_buffer_pool_get_config (dev->pool);
  gst_buffer_pool_config_set_params (config, NULL, 0,
      GST_DROIDCAMSRC_NUM_BUFFERS, GST_DROIDCAMSRC_NUM_BUFFERS);

  if (!gst_buffer_pool_set_config (dev->pool, config)) {
    GST_ERROR ("Failed to configure buffer pool");
    return FALSE;
  }

  /* now the callbacks */
  {
    DroidMediaCameraCallbacks cb;

    cb.shutter_cb = gst_droidcamsrc_dev_shutter_callback;
    cb.focus_cb = gst_droidcamsrc_dev_focus_callback;
    cb.focus_move_cb = gst_droidcamsrc_dev_focus_move_callback;
    cb.error_cb = gst_droidcamsrc_dev_error_callback;
    cb.zoom_cb = gst_droidcamsrc_dev_zoom_callback;
    cb.raw_image_cb = gst_droidcamsrc_dev_raw_image_callback;
    cb.compressed_image_cb = gst_droidcamsrc_dev_compressed_image_callback;
    cb.postview_frame_cb = gst_droidcamsrc_dev_postview_frame_callback;
    cb.raw_image_notify_cb = gst_droidcamsrc_dev_raw_image_notify_callback;
    cb.preview_frame_cb = gst_droidcamsrc_dev_preview_frame_callback;
    cb.video_frame_cb = gst_droidcamsrc_dev_video_frame_callback;
    cb.preview_metadata_cb = gst_droidcamsrc_dev_preview_metadata_callback;
    droid_media_camera_set_callbacks (dev->cam, &cb, dev);
  }

  {
    DroidMediaBufferQueueCallbacks cb;
    cb.buffers_released = gst_droidcamsrc_dev_buffers_released;
    cb.frame_available = gst_droidcamsrc_dev_frame_available;
    droid_media_buffer_queue_set_callbacks (dev->queue, &cb, dev);
  }

  gst_droidcamsrc_dev_update_params_locked (dev);

  g_rec_mutex_unlock (dev->lock);

  return TRUE;
}
예제 #18
0
void
gst_droidcamsrc_dev_deinit (GstDroidCamSrcDev * dev)
{
  GST_DEBUG ("dev deinit");

  g_rec_mutex_lock (dev->lock);

  if (dev->params) {
    gst_droidcamsrc_params_destroy (dev->params);
    dev->params = NULL;
  }

  g_rec_mutex_unlock (dev->lock);
}
예제 #19
0
/*
 * Cleans any remaining data on the web server
 */
void
_gda_web_do_server_cleanup (GdaConnection *cnc, WebConnectionData *cdata)
{
	SoupMessage *msg;
	guint status;
	gchar *real_url;
	gint nb_retries;

	/* wait for worker to finish */
	g_rec_mutex_lock (& (cdata->mutex));
	for (nb_retries = 0; (nb_retries < 10) && cdata->worker_running; nb_retries ++) {
		g_rec_mutex_unlock (& (cdata->mutex));
		g_usleep (50000);
		g_rec_mutex_lock (& (cdata->mutex));
	}
	g_rec_mutex_unlock (& (cdata->mutex));
 
	real_url = g_strdup_printf ("%s/gda-clean.php?%s", cdata->server_base_url, cdata->session_id);
	msg = soup_message_new ("GET", real_url);
	if (!msg) {
		gda_connection_add_event_string (cnc, _("Invalid HOST/SCRIPT '%s'"), real_url);
 		g_free (real_url);
		return;
 	}
	g_free (real_url);

	g_object_set (G_OBJECT (cdata->front_session), SOUP_SESSION_TIMEOUT, 5, NULL);
	status = soup_session_send_message (cdata->front_session, msg);
	g_object_unref (msg);

	if (!SOUP_STATUS_IS_SUCCESSFUL (status))
		g_warning (_("Error cleaning data on the server for session %s"), cdata->session_id);
#ifdef DEBUG_WEB_PROV
	else
		g_print ("CLEANUP DONE!\n");
#endif
}
예제 #20
0
void
gst_droidcamsrc_dev_close (GstDroidCamSrcDev * dev)
{
  GST_DEBUG ("dev close");

  g_rec_mutex_lock (dev->lock);

  if (dev->cam) {
    droid_media_camera_disconnect (dev->cam);
    dev->cam = NULL;
    dev->queue = NULL;
  }

  g_rec_mutex_unlock (dev->lock);
}
예제 #21
0
static void
	stop_eos_task (GstAmlVdec *amlvdec)
{
    if (! amlvdec->eos_task)
        return;

    gst_task_stop (amlvdec->eos_task);

    g_rec_mutex_lock (&amlvdec->eos_lock);

    g_rec_mutex_unlock (&amlvdec->eos_lock);
    gst_task_join (amlvdec->eos_task);
    gst_object_unref (amlvdec->eos_task);
    amlvdec->eos_task = NULL;
}
예제 #22
0
/* returns FALSE if cancelled, in which case the lock is not held */
gboolean
e_mapi_cancellable_rec_mutex_lock (EMapiCancellableRecMutex *rec_mutex,
				   GCancellable *cancellable,
				   GError **error)
{
	gulong handler_id;
	gboolean res = TRUE;

	g_return_val_if_fail (rec_mutex != NULL, FALSE);

	g_mutex_lock (&rec_mutex->cond_mutex);
	if (!cancellable) {
		g_mutex_unlock (&rec_mutex->cond_mutex);
		g_rec_mutex_lock (&rec_mutex->rec_mutex);
		return TRUE;
	}

	if (g_cancellable_is_cancelled (cancellable)) {
		if (error && !*error) {
			/* coverity[unchecked_value] */
			g_cancellable_set_error_if_cancelled (cancellable, error);
		}
		g_mutex_unlock (&rec_mutex->cond_mutex);
		return FALSE;
	}

	handler_id = g_signal_connect (cancellable, "cancelled",
		G_CALLBACK (cancellable_rec_mutex_cancelled_cb), rec_mutex);

	while (!g_rec_mutex_trylock (&rec_mutex->rec_mutex)) {
		/* recheck once per 10 seconds, just in case */
		g_cond_wait_until (&rec_mutex->cond, &rec_mutex->cond_mutex,
			g_get_monotonic_time () + (10 * G_TIME_SPAN_SECOND));

		if (g_cancellable_is_cancelled (cancellable)) {
			if (error && !*error)
				g_cancellable_set_error_if_cancelled (cancellable, error);
			res = FALSE;
			break;
		}
	}

	g_signal_handler_disconnect (cancellable, handler_id);

	g_mutex_unlock (&rec_mutex->cond_mutex);

	return res;
}
예제 #23
0
static gboolean
on_timer_source_ready (GObject *stream, GoaAlarm *self)
{
  gint64 number_of_fires;
  gssize bytes_read;
  gboolean run_again = FALSE;
  GError *error = NULL;

  g_return_val_if_fail (GOA_IS_ALARM (self), FALSE);

  g_rec_mutex_lock (&self->priv->lock);

  if (self->priv->type != GOA_ALARM_TYPE_TIMER)
    {
      g_warning ("GoaAlarm: timer source ready callback called "
                 "when timer source isn't supposed to be used. "
                 "Current timer type is %u", self->priv->type);
      goto out;
    }

  bytes_read =
    g_pollable_input_stream_read_nonblocking (G_POLLABLE_INPUT_STREAM (stream),
                                              &number_of_fires, sizeof (gint64),
                                              NULL, &error);

  if (bytes_read < 0)
    {
      g_warning ("GoaAlarm: failed to read from timer fd: %s\n",
                 error->message);
      g_error_free (error);
      goto out;
    }

  if (bytes_read == sizeof (gint64))
    {
      if (number_of_fires < 0 || number_of_fires > 1)
        {
          g_warning ("GoaAlarm: expected timerfd to report firing once,"
                     "but it reported firing %ld times\n", (long) number_of_fires);
        }
    }

  fire_or_rearm_alarm (self);
  run_again = TRUE;
out:
  g_rec_mutex_unlock (&self->priv->lock);
  return run_again;
}
예제 #24
0
/**
 * camel_binding_bind_property:
 * @source: (type GObject.Object): the source #GObject
 * @source_property: the property on @source to bind
 * @target: (type GObject.Object): the target #GObject
 * @target_property: the property on @target to bind
 * @flags: flags to pass to #GBinding
 *
 * Thread safe variant of g_object_bind_property(). See its documentation
 * for more information on arguments and return value.
 *
 * Returns: (transfer none):
 *
 * Since: 3.16
 **/
GBinding *
camel_binding_bind_property (gpointer source,
			     const gchar *source_property,
			     gpointer target,
			     const gchar *target_property,
			     GBindingFlags flags)
{
	GBinding *binding;

	g_rec_mutex_lock (&camel_binding_lock);

	binding = g_object_bind_property (source, source_property, target, target_property, flags);

	g_rec_mutex_unlock (&camel_binding_lock);

	return binding;
}
예제 #25
0
gchar *
tracker_locale_get (TrackerLocaleID id)
{
	gchar *locale;

	g_return_val_if_fail (initialized, NULL);

	g_rec_mutex_lock (&locales_mutex);

	/* Always return a duplicated string, as the locale may change at any
	 * moment */
	locale = g_strdup (current_locales[id]);

	g_rec_mutex_unlock (&locales_mutex);

	return locale;
}
예제 #26
0
void
tracker_locale_set (TrackerLocaleID  id,
                    const gchar     *value)
{
	g_rec_mutex_lock (&locales_mutex);

	if (current_locales[id]) {
		g_debug ("Locale '%s' was changed from '%s' to '%s'",
		         locale_names[id],
		         current_locales[id],
		         value);
		g_free (current_locales[id]);
	} else {
		g_debug ("Locale '%s' was set to '%s'",
		         locale_names[id],
		         value);
	}

	/* Store the new one */
	current_locales[id] = g_strdup (value);

	/* And also set the new one in the corresponding envvar */
	switch (id) {
	case TRACKER_LOCALE_LANGUAGE:
		g_setenv ("LANG", value, TRUE);
		break;
	case TRACKER_LOCALE_TIME:
		setlocale (LC_TIME, value);
		break;
	case TRACKER_LOCALE_COLLATE:
		setlocale (LC_COLLATE, value);
		break;
	case TRACKER_LOCALE_NUMERIC:
		setlocale (LC_NUMERIC, value);
		break;
	case TRACKER_LOCALE_MONETARY:
		setlocale (LC_MONETARY, value);
		break;
	case TRACKER_LOCALE_LAST:
		/* Make compiler happy */
		g_warn_if_reached ();
		break;
	}

	g_rec_mutex_unlock (&locales_mutex);
}
예제 #27
0
static gboolean
on_timeout_source_ready (GoaAlarm *self)
{
  g_return_val_if_fail (GOA_IS_ALARM (self), FALSE);

  g_rec_mutex_lock (&self->priv->lock);

  if (self->priv->type == GOA_ALARM_TYPE_UNSCHEDULED)
    goto out;

  fire_or_rearm_alarm (self);

  schedule_wakeups_with_timeout_source (self);

out:
  g_rec_mutex_unlock (&self->priv->lock);
  return FALSE;
}
예제 #28
0
static void
gst_droidcamsrc_dev_release_recording_frame (void *data,
    GstDroidCamSrcDevVideoData * video_data)
{
  GstDroidCamSrcDev *dev;

  GST_DEBUG ("dev release recording frame %p", data);

  dev = video_data->dev;

  g_rec_mutex_lock (dev->lock);
  --dev->vid->queued_frames;

  droid_media_camera_release_recording_frame (dev->cam, video_data->data);

  g_slice_free (GstDroidCamSrcDevVideoData, video_data);
  g_rec_mutex_unlock (dev->lock);
}
예제 #29
0
gchar *
tracker_locale_get (TrackerLocaleID id)
{
	const gchar *env_locale = NULL;
	gchar *locale;

	g_rec_mutex_lock (&locales_mutex);

	env_locale = tracker_locale_get_unlocked (id);

	/* Always return a duplicated string, as the locale may change at any
	 * moment */
	locale = g_strdup (env_locale);

	g_rec_mutex_unlock (&locales_mutex);

	return locale;
}
예제 #30
0
static void
goa_alarm_set_time (GoaAlarm *self, GDateTime *time)
{
  g_rec_mutex_lock (&self->priv->lock);

  g_date_time_ref (time);
  self->priv->time = time;

  if (self->priv->context == NULL)
    self->priv->context = g_main_context_ref (g_main_context_default ());

  schedule_wakeups (self);

  /* Wake up right away, in case it's already expired leaving the gate */
  schedule_immediate_wakeup (self);
  g_rec_mutex_unlock (&self->priv->lock);
  g_object_notify (G_OBJECT (self), "time");
}