struct source {
int timeout;
- sr_receive_data_callback_t cb;
+ sr_receive_data_callback cb;
void *cb_data;
/* This is used to keep track of the object (fd, pollfd or channel) which is
};
struct datafeed_callback {
- sr_datafeed_callback_t cb;
+ sr_datafeed_callback cb;
void *cb_data;
};
*
* @retval NULL Error.
* @retval other A pointer to the newly allocated session.
+ *
+ * @since 0.1.0
*/
SR_API struct sr_session *sr_session_new(void)
{
*
* @retval SR_OK Success.
* @retval SR_ERR_BUG No session exists.
+ *
+ * @since 0.1.0
*/
SR_API int sr_session_destroy(void)
{
*
* @retval SR_OK Success.
* @retval SR_ERR_BUG No session exists.
+ *
+ * @since 0.1.0
*/
SR_API int sr_session_dev_remove_all(void)
{
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_BUG No session exists.
+ *
+ * @since 0.2.0
*/
SR_API int sr_session_dev_add(const struct sr_dev_inst *sdi)
{
*
* @retval SR_OK Success.
* @retval SR_ERR Invalid argument.
+ *
+ * @since 0.3.0
*/
SR_API int sr_session_dev_list(GSList **devlist)
{
*
* @retval SR_OK Success.
* @retval SR_ERR_BUG No session exists.
+ *
+ * @since 0.1.0
*/
SR_API int sr_session_datafeed_callback_remove_all(void)
{
*
* @retval SR_OK Success.
* @retval SR_ERR_BUG No session exists.
+ *
+ * @since 0.3.0
*/
-SR_API int sr_session_datafeed_callback_add(sr_datafeed_callback_t cb, void *cb_data)
+SR_API int sr_session_datafeed_callback_add(sr_datafeed_callback cb, void *cb_data)
{
struct datafeed_callback *cb_struct;
return SR_OK;
}
+SR_PRIV struct sr_trigger *sr_session_trigger_get(void)
+{
+ return session->trigger;
+}
+
+SR_API int sr_session_trigger_set(struct sr_trigger *trig)
+{
+ session->trigger = trig;
+
+ return SR_OK;
+}
+
/**
* Call every device in the session's callback.
*
return SR_OK;
}
+
+static int verify_trigger(struct sr_trigger *trigger)
+{
+ struct sr_trigger_stage *stage;
+ struct sr_trigger_match *match;
+ GSList *l, *m;
+
+ if (!trigger->stages) {
+ sr_err("No trigger stages defined.");
+ return SR_ERR;
+ }
+
+ sr_spew("Checking trigger:");
+ for (l = trigger->stages; l; l = l->next) {
+ stage = l->data;
+ if (!stage->matches) {
+ sr_err("Stage %d has no matches defined.", stage->stage);
+ return SR_ERR;
+ }
+ for (m = stage->matches; m; m = m->next) {
+ match = m->data;
+ if (!match->channel) {
+ sr_err("Stage %d match has no channel.", stage->stage);
+ return SR_ERR;
+ }
+ if (!match->match) {
+ sr_err("Stage %d match is not defined.", stage->stage);
+ return SR_ERR;
+ }
+ sr_spew("Stage %d match on channel %s, match %d", stage->stage,
+ match->channel->name, match->match);
+ }
+ }
+
+ return SR_OK;
+}
/**
* Start a session.
*
*
* @retval SR_OK Success.
* @retval SR_ERR Error occured.
+ *
+ * @since 0.1.0
*/
SR_API int sr_session_start(void)
{
return SR_ERR_BUG;
}
+ if (session->trigger && verify_trigger(session->trigger) != SR_OK)
+ return SR_ERR;
+
sr_info("Starting.");
ret = SR_OK;
*
* @retval SR_OK Success.
* @retval SR_ERR_BUG Error occured.
+ *
+ * @since 0.1.0
*/
SR_API int sr_session_run(void)
{
*
* @retval SR_OK Success.
* @retval SR_ERR_BUG No session exists.
+ *
+ * @since 0.1.0
*/
SR_API int sr_session_stop(void)
{
break;
case SR_DF_LOGIC:
logic = packet->payload;
- sr_dbg("bus: Received SR_DF_LOGIC packet (%" PRIu64 " bytes).",
- logic->length);
+ sr_dbg("bus: Received SR_DF_LOGIC packet (%" PRIu64 " bytes, "
+ "unitsize = %d).", logic->length, logic->unitsize);
break;
case SR_DF_ANALOG:
analog = packet->payload;
* @retval SR_ERR_MALLOC Memory allocation error.
*/
static int _sr_session_source_add(GPollFD *pollfd, int timeout,
- sr_receive_data_callback_t cb, void *cb_data, gintptr poll_object)
+ sr_receive_data_callback cb, void *cb_data, gintptr poll_object)
{
struct source *new_sources, *s;
GPollFD *new_pollfds;
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
+ *
+ * @since 0.3.0
*/
SR_API int sr_session_source_add(int fd, int events, int timeout,
- sr_receive_data_callback_t cb, void *cb_data)
+ sr_receive_data_callback cb, void *cb_data)
{
GPollFD p;
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
+ *
+ * @since 0.3.0
*/
SR_API int sr_session_source_add_pollfd(GPollFD *pollfd, int timeout,
- sr_receive_data_callback_t cb, void *cb_data)
+ sr_receive_data_callback cb, void *cb_data)
{
return _sr_session_source_add(pollfd, timeout, cb,
cb_data, (gintptr)pollfd);
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
+ *
+ * @since 0.3.0
*/
SR_API int sr_session_source_add_channel(GIOChannel *channel, int events,
- int timeout, sr_receive_data_callback_t cb, void *cb_data)
+ int timeout, sr_receive_data_callback cb, void *cb_data)
{
GPollFD p;
* @retval SR_ERR_ARG Invalid argument
* @retval SR_ERR_MALLOC Memory allocation error.
* @retval SR_ERR_BUG Internal error.
+ *
+ * @since 0.3.0
*/
SR_API int sr_session_source_remove(int fd)
{
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
* SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon
* internal errors.
+ *
+ * @since 0.2.0
*/
SR_API int sr_session_source_remove_pollfd(GPollFD *pollfd)
{
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
* @return SR_ERR_BUG Internal error.
+ *
+ * @since 0.2.0
*/
SR_API int sr_session_source_remove_channel(GIOChannel *channel)
{