Example #1
0
/**
 * msg_queue_send_names:
 *
 *
 * returns FALSE if we never received a keepalive, so the server process seems to be non-responsive
 */
static gboolean msg_queue_send_names(gint send_with_id, GList * names, gboolean received_keepalive)
{
	struct msgbuf {
		long mtype;
		char mtext[MSQ_QUEUE_SIZE];
	} msgp;
	gint success = 1, check_keepalive_cnt = 0, send_failure_cnt = 0;
	GList *tmplist;
	
	/* we have a message queue now, opened by another bluefish process */
	msgp.mtype = send_with_id;
	tmplist = g_list_first(names);
	while (tmplist && success) {
		gint retval;
		gint len = strlen((gchar *) tmplist->data);

		/* we start with checking for keepalives */
		if (!received_keepalive) {
			if (msg_queue_check_alive(TRUE)) {
				received_keepalive = TRUE;
				DEBUG_MSG("msg_queue_send_files, received keepalive\n");
			} else {
				check_keepalive_cnt++;
				DEBUG_MSG("msg_queue_send_files, no keepalive (try %d)\n", check_keepalive_cnt);
			}
		}
		
		if (len < MSQ_QUEUE_SIZE - 1) {
			strncpy(msgp.mtext, (gchar *) tmplist->data, MSQ_QUEUE_SIZE - 1);
			retval = msgsnd(msg_queue.msgid, (void *) &msgp, MSQ_QUEUE_SIZE * sizeof(char), IPC_NOWAIT);
			if (retval == -1) {
				DEBUG_MSG("msg_queue_send_files, failed sending, errno=%d\n", errno);
				if (errno == EAGAIN) { /* EAGAIN = 11 */
					static struct timespec const req = { 0, MSG_QUEUE_PER_DOCUMENT_TIMEOUT};
					static struct timespec rem;
					nanosleep(&req, &rem);
					send_failure_cnt++;
				} else {
					DEBUG_MSG("msg_queue_send_files, failing to send, errno=%d, aborting\n", errno);
					success = 0;
				}
			} else {
				if (!received_keepalive) {
					/* if we fill the message queue with loads of data, the server 
					   process doesn't even get a chance of reply-ing. So as long as we 
					   don't know a thing about it, we give it some time and check for
					   a reply often */
					if (msg_queue_check_alive(TRUE)) {
						received_keepalive = TRUE;
						DEBUG_MSG("msg_queue_send_files, received keepalive\n");
					} else {
						check_keepalive_cnt++;
						DEBUG_MSG("msg_queue_send_files, no keepalive (try %d)\n", check_keepalive_cnt);
					}
				}
				DEBUG_MSG("msg_queue_send_files, sending %s succeeded\n", (gchar *) tmplist->data);
				send_failure_cnt = 0;
				tmplist = g_list_next(tmplist);
			}
		} else {
			DEBUG_MSG("msg_queue_send_files, failed sending, length increased message size\n");
			success = 0;
		}
		if ((check_keepalive_cnt > 5) || (send_failure_cnt > 60)) {
			DEBUG_MSG
				("msg_queue_send_files, to many tries, check_keepalive_cnt=%d, send_failure_cnt=%d\n",
				 check_keepalive_cnt, send_failure_cnt);
			success = 0;
		}
	}
	if (success) {
		DEBUG_MSG
			("msg_queue_send_files, sending filenames complete and successfull, received_keepalive=%d\n",
			 received_keepalive);
/*		/ * all filenames send to other process, test if it is alive * /
		if (received_keepalive) {
			exit(0);
		} else {
			/ * the other process should have enough time to check the queue * /
			/ * the macro is in milliseconds, usleep is microseconds * /
			if (msg_queue_check_alive(TRUE)) {
				/ * we did receive a keep alive message! * /
				exit(0);
			}
		}*/
		return received_keepalive;
	}
	return FALSE;
}
Example #2
0
/* get next announcement entry */
SaErrorT oh_announcement_get_next(oh_announcement *ann, SaHpiSeverityT sev,
                                  SaHpiBoolT ack, SaHpiAnnouncementT *entry)
{
        oh_ann_entry *myentry;
        GList *annlist;
        int notinset;

        if (ann == NULL || entry == NULL) {
                return SA_ERR_HPI_INVALID_PARAMS;
        }
        if (g_list_length(ann->annentries) == 0) {
                return SA_ERR_HPI_NOT_PRESENT;
        }

        /* get the first physical entry */
        annlist = g_list_first(ann->annentries);

        if (entry->EntryId == SAHPI_FIRST_ENTRY) {
                /* find the first logical entry */
                notinset = FALSE;
                while (annlist != NULL) {
                        myentry = (oh_ann_entry *) annlist->data;
                        if (notinset == FALSE &&
                            sev != SAHPI_ALL_SEVERITIES &&
                            sev == myentry->annentry.Severity)
                                notinset = TRUE;
                        if (notinset == FALSE &&
                            ack == TRUE &&
                            myentry->annentry.Acknowledged != TRUE)
                                notinset = TRUE;
                        if (notinset == FALSE)
                                break;
                        notinset = FALSE;
                        annlist = g_list_next(annlist);
                }
                if (annlist == NULL) {
                        return SA_ERR_HPI_NOT_PRESENT;
                }
                memcpy(entry, &myentry->annentry, sizeof(SaHpiAnnouncementT));
                return SA_OK;
        }

        /* find the start matching entry */
        while (annlist != NULL) {
                myentry = (oh_ann_entry *) annlist->data;
                if (entry->EntryId == myentry->annentry.EntryId &&
                    entry->Timestamp == myentry->annentry.Timestamp)
                        break;
                annlist = g_list_next(annlist);
        }
        if (annlist == NULL) {
                return SA_ERR_HPI_NOT_PRESENT;
        }

        /* find the next logical entry */
        notinset = FALSE;
        annlist = g_list_next(annlist);
        while (annlist != NULL) {
                myentry = (oh_ann_entry *) annlist->data;
                if (notinset == FALSE &&
                    sev != SAHPI_ALL_SEVERITIES &&
                    sev == myentry->annentry.Severity)
                        notinset = TRUE;
                if (notinset == FALSE &&
                    ack == TRUE && myentry->annentry.Acknowledged != TRUE)
                        notinset = TRUE;
                if (notinset == FALSE)
                        break;
                notinset = FALSE;
                annlist = g_list_next(annlist);
        }
        if (annlist == NULL) {
                return SA_ERR_HPI_NOT_PRESENT;
        }

        /* found a matching announcement */
        memcpy(entry, &myentry->annentry, sizeof(SaHpiAnnouncementT));
        return SA_OK;
}
Example #3
0
static void
campfire_ssl_connect(CampfireConn * campfire,
		     G_GNUC_UNUSED PurpleInputCondition cond,
		     gboolean from_connection_callback)
{
	GList *first = NULL;
	CampfireSslTransaction *xaction = NULL;

	purple_debug_info("campfire", "%s\n", __FUNCTION__);
	if (!campfire) {
		return;
	} else {
		first = g_list_first(campfire->queue);
	}

	if (!first) {
		return;
	} else {
		xaction = first->data;
	}

	if (!xaction) {
		return;
	}

	if (!campfire->gsc) {
		purple_debug_info("campfire", "new ssl connection\n");
		campfire->gsc = purple_ssl_connect(campfire->account,
						   campfire->hostname,
						   443, (PurpleSslInputFunction)
						   (campfire_ssl_connect_cb),
						   campfire_ssl_failure,
						   campfire);
		purple_debug_info("campfire",
				  "new ssl connection kicked off.\n");
	} else {
		purple_debug_info("campfire", "previous ssl connection\n");
		/* we want to write our http request to the ssl connection
		 * WHENEVER this is called from the callback (meaning we've
		 * JUST NOW established the connection). OR when the first
		 * transaction is added to the queue on an OPEN ssl connection
		 */
		if (from_connection_callback
		    || g_list_length(campfire->queue) == 1) {
			/* campfire_ssl_handler is the ONLY input handler we
			 * EVER use So... if there is already an input handler
			 * present (inpa > 0), then we DON"T want to add another
			 * input handler.  Quite a few hours spent chasing bugs
			 * when multiple input handlers were added!
			 */
			if (campfire->gsc->inpa == 0) {
				purple_debug_info("campfire", "adding input\n");
				purple_ssl_input_add(campfire->gsc,
						     (PurpleSslInputFunction)
						     (campfire_ssl_handler),
						     campfire);
			}
			purple_debug_info("campfire",
					  "writing first request on ssl connection\n");
			purple_ssl_write(campfire->gsc,
					 xaction->http_request->str,
					 xaction->http_request->len);
		}
	}
	return;
}
static GstFlowReturn
gst_cutter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
{
  GstFlowReturn ret = GST_FLOW_OK;
  GstCutter *filter;
  GstMapInfo map;
  gint16 *in_data;
  gint bpf, rate;
  gsize in_size;
  guint num_samples;
  gdouble NCS = 0.0;            /* Normalized Cumulative Square of buffer */
  gdouble RMS = 0.0;            /* RMS of signal in buffer */
  gdouble NMS = 0.0;            /* Normalized Mean Square of buffer */
  GstBuffer *prebuf;            /* pointer to a prebuffer element */
  GstClockTime duration;

  filter = GST_CUTTER (parent);

  if (GST_AUDIO_INFO_FORMAT (&filter->info) == GST_AUDIO_FORMAT_UNKNOWN)
    goto not_negotiated;

  bpf = GST_AUDIO_INFO_BPF (&filter->info);
  rate = GST_AUDIO_INFO_RATE (&filter->info);

  gst_buffer_map (buf, &map, GST_MAP_READ);
  in_data = (gint16 *) map.data;
  in_size = map.size;

  GST_LOG_OBJECT (filter, "length of prerec buffer: %" GST_TIME_FORMAT,
      GST_TIME_ARGS (filter->pre_run_length));

  /* calculate mean square value on buffer */
  switch (GST_AUDIO_INFO_FORMAT (&filter->info)) {
    case GST_AUDIO_FORMAT_S16:
      num_samples = in_size / 2;
      gst_cutter_calculate_gint16 (in_data, num_samples, &NCS);
      NMS = NCS / num_samples;
      break;
    case GST_AUDIO_FORMAT_S8:
      num_samples = in_size;
      gst_cutter_calculate_gint8 ((gint8 *) in_data, num_samples, &NCS);
      NMS = NCS / num_samples;
      break;
    default:
      /* this shouldn't happen */
      g_warning ("no mean square function for format");
      break;
  }

  gst_buffer_unmap (buf, &map);

  filter->silent_prev = filter->silent;

  duration = gst_util_uint64_scale (in_size / bpf, GST_SECOND, rate);

  RMS = sqrt (NMS);
  /* if RMS below threshold, add buffer length to silent run length count
   * if not, reset
   */
  GST_LOG_OBJECT (filter, "buffer stats: NMS %f, RMS %f, audio length %f", NMS,
      RMS, gst_guint64_to_gdouble (duration));

  if (RMS < filter->threshold_level)
    filter->silent_run_length += gst_guint64_to_gdouble (duration);
  else {
    filter->silent_run_length = 0 * GST_SECOND;
    filter->silent = FALSE;
  }

  if (filter->silent_run_length > filter->threshold_length)
    /* it has been silent long enough, flag it */
    filter->silent = TRUE;

  /* has the silent status changed ? if so, send right signal
   * and, if from silent -> not silent, flush pre_record buffer
   */
  if (filter->silent != filter->silent_prev) {
    if (filter->silent) {
      GstMessage *m =
          gst_cutter_message_new (filter, FALSE, GST_BUFFER_TIMESTAMP (buf));
      GST_DEBUG_OBJECT (filter, "signaling CUT_STOP");
      gst_element_post_message (GST_ELEMENT (filter), m);
    } else {
      gint count = 0;
      GstMessage *m =
          gst_cutter_message_new (filter, TRUE, GST_BUFFER_TIMESTAMP (buf));

      GST_DEBUG_OBJECT (filter, "signaling CUT_START");
      gst_element_post_message (GST_ELEMENT (filter), m);
      /* first of all, flush current buffer */
      GST_DEBUG_OBJECT (filter, "flushing buffer of length %" GST_TIME_FORMAT,
          GST_TIME_ARGS (filter->pre_run_length));

      while (filter->pre_buffer) {
        prebuf = (g_list_first (filter->pre_buffer))->data;
        filter->pre_buffer = g_list_remove (filter->pre_buffer, prebuf);
        gst_pad_push (filter->srcpad, prebuf);
        ++count;
      }
      GST_DEBUG_OBJECT (filter, "flushed %d buffers", count);
      filter->pre_run_length = 0 * GST_SECOND;
    }
  }
  /* now check if we have to send the new buffer to the internal buffer cache
   * or to the srcpad */
  if (filter->silent) {
    filter->pre_buffer = g_list_append (filter->pre_buffer, buf);
    filter->pre_run_length += gst_guint64_to_gdouble (duration);

    while (filter->pre_run_length > filter->pre_length) {
      GstClockTime pduration;
      gsize psize;

      prebuf = (g_list_first (filter->pre_buffer))->data;
      g_assert (GST_IS_BUFFER (prebuf));

      psize = gst_buffer_get_size (prebuf);
      pduration = gst_util_uint64_scale (psize / bpf, GST_SECOND, rate);

      filter->pre_buffer = g_list_remove (filter->pre_buffer, prebuf);
      filter->pre_run_length -= gst_guint64_to_gdouble (pduration);

      /* only pass buffers if we don't leak */
      if (!filter->leaky)
        ret = gst_pad_push (filter->srcpad, prebuf);
      else
        gst_buffer_unref (prebuf);
    }
  } else
    ret = gst_pad_push (filter->srcpad, buf);

  return ret;

  /* ERRORS */
not_negotiated:
  {
    return GST_FLOW_NOT_NEGOTIATED;
  }
}
Example #5
0
void
campfire_ssl_handler(CampfireConn * campfire,
		     PurpleSslConnection * gsc, PurpleInputCondition cond)
{
	GList *first = g_list_first(campfire->queue);
	CampfireSslTransaction *xaction = NULL;
	gint status;
	gboolean close_ssl = FALSE;
	gboolean cleanup = TRUE;

	if (first) {
		xaction = first->data;
	} else {
		xaction = g_new0(CampfireSslTransaction, 1);
		campfire->num_xaction_malloc++; /* valgrind investigation */
		purple_debug_info("campfire", "%s: xaction: %p, campfire->num_xaction_malloc:%d\n",
		                  __FUNCTION__, xaction, campfire->num_xaction_malloc);
		xaction->campfire = campfire;
	}

	purple_debug_info("campfire", "%s: first: %p\n", __FUNCTION__, first);

	status = campfire_http_response(gsc, xaction, cond,
					&(xaction->xml_response));
	purple_debug_info("campfire", "http status: %d\n", status);

	if (status == 200 || status == 201) {
		xaction->xml_response =
			xmlnode_from_str(xaction->http_response.content->str,
					 -1);
		if (xaction && xaction->response_cb) {
			purple_debug_info("campfire",
			                  "calling response_cb (%p)\n",
			                  xaction->response_cb);
			xaction->response_cb(xaction, gsc, cond);
		}
		cleanup = TRUE;
	} else if (status == 0) {	/*received partial content */
		cleanup = FALSE;
	} else {		/*status < 0 or some other http status we don't expect */

		close_ssl = TRUE;
		cleanup = TRUE;
	}

	if (close_ssl && campfire->gsc) {
		purple_debug_info("campfire",
				  "closing ssl connection:%p (%p)\n", gsc,
				  campfire->gsc);
		campfire->gsc = NULL;
		purple_ssl_close(gsc);
		cleanup = TRUE;
	}

	if (cleanup) {
		campfire_xaction_free(xaction);

		if (first) {
			purple_debug_info("campfire",
					  "removing from queue: length: %d\n",
					  g_list_length(campfire->queue));
			campfire->queue =
				g_list_remove(campfire->queue, xaction);
			purple_debug_info("campfire",
					  "removed from queue: length: %d\n",
					  g_list_length(campfire->queue));
		}

		first = g_list_first(campfire->queue);
		if (first) {
			xaction = first->data;
			purple_debug_info("campfire",
					  "writing subsequent request on ssl connection\n");
			purple_ssl_write(gsc, xaction->http_request->str,
					 xaction->http_request->len);
		}
	}
}