err_t http_cache_lookup (const char *name, struct http_conn *cs) { struct http_cache_entry *e; assert(cs != NULL); e = find_cacheline(name); if (e->valid == 1) { /* fresh matching cache-entry found */ DEBUGPRINT ("%d: Fresh cache-entry, returning page [%s]\n", cs->request_no, name); trigger_callback (cs, e); return ERR_OK; } /* end if: valid cacheline */ /* data not in cache */ /* add this connection to the list of waiting on cacheline */ add_connection (e, cs); /* Check if no-one is loading the data */ if (e->loading == 0 ) { e->loading = 1; DEBUGPRINT ("%d: starting the page loading\n", cs->request_no); async_load_cache_entry(e); } /* end if: no-one else is loading the data */ else { DEBUGPRINT ("%d: someone else is loading the page, so just waiting\n", cs->request_no); } return ERR_OK; } /* end function: http_cache_lookup */
/* send callback for each pending http_conn */ static void handle_pending_list(struct http_cache_entry *e) { struct http_conn *cs = NULL; struct http_conn *next_cs = NULL; if(e == NULL) { printf("ERROR: handle_pending_list: null passed for cache entry\n"); return; } if(e->conn == NULL){ // printf("ERROR: handle_pending_list: no one waiting\n"); return; } cs = e->conn; while (cs != NULL) { e->conn = cs->next; trigger_callback(cs, e); next_cs = cs->next; /* Copying the next of cs as following function can release the cs. */ decrement_http_conn_reference(cs); cs = next_cs; } /* clear the list attached to the cache */ e->conn = NULL; e->last = NULL; } /* end function : handle_pending_list */
void scsicb_device::scsi_in( UINT32 data, UINT32 mask ) { linestate = data; trigger_callback( mask, SCSI_MASK_BSY, m_bsy_handler ); trigger_callback( mask, SCSI_MASK_SEL, m_sel_handler ); trigger_callback( mask, SCSI_MASK_CD, m_cd_handler ); trigger_callback( mask, SCSI_MASK_IO, m_io_handler ); trigger_callback( mask, SCSI_MASK_MSG, m_msg_handler ); trigger_callback( mask, SCSI_MASK_REQ, m_req_handler ); trigger_callback( mask, SCSI_MASK_ACK, m_ack_handler ); trigger_callback( mask, SCSI_MASK_ATN, m_atn_handler ); trigger_callback( mask, SCSI_MASK_RST, m_rst_handler ); }
static int test_callback_add_remove(void) { struct device *dev = device_get_binding(DEV_NAME); /* SetUp: initialize environment */ init_callback(dev); /* 3. enable callback, trigger PIN_IN interrupt by operate PIN_OUT */ trigger_callback(dev, 1); /*= checkpoint: check callback is triggered =*/ if (cb_cnt[0] != 1 || cb_cnt[1] != 1) { TC_ERROR("not trigger callback correctly\n"); goto err_exit; } /* 4. remove callback_1 */ gpio_remove_callback(dev, &cb_data[0].gpio_cb); trigger_callback(dev, 1); /*= checkpoint: check callback is triggered =*/ if (cb_cnt[0] != 0 || cb_cnt[1] != 1) { TC_ERROR("not trigger callback correctly\n"); goto err_exit; } /* 5. remove callback_2 */ gpio_remove_callback(dev, &cb_data[1].gpio_cb); trigger_callback(dev, 1); /*= checkpoint: check callback is triggered =*/ if (cb_cnt[0] != 0 || cb_cnt[1] != 0) { TC_ERROR("not trigger callback correctly\n"); goto err_exit; } return TC_PASS; err_exit: gpio_remove_callback(dev, &cb_data[0].gpio_cb); gpio_remove_callback(dev, &cb_data[1].gpio_cb); return TC_FAIL; }
int GStreamer_stop() { GstStateChangeReturn ret; GstState state, pending; g_print("GStreamer: stop\n"); if (!g_initialized) { g_error("GStreamer: library not initialized!\n"); return -1; } pthread_mutex_lock(&g_mutex); g_duration = 0; g_position = 0; /* */ gst_element_get_state(GST_ELEMENT(g_pipeline), &state, &pending, GST_CLOCK_TIME_NONE); ret = gst_element_set_state(GST_ELEMENT(g_pipeline), GST_STATE_NULL); if (ret == GST_STATE_CHANGE_FAILURE) { g_error("Failed to stop pipeline ret == %d\n", ret); pthread_mutex_unlock(&g_mutex); return -1; } gst_element_get_state(GST_ELEMENT(g_pipeline), &state, &pending, GST_CLOCK_TIME_NONE); g_print("GStreamer: State change: CUR: '%s', PENDING: '%s'\n", gststate_get_name(state), gststate_get_name(pending)); #if 0 /* TODO, hmm */ trigger_callback(GST_STATE_NULL); #endif pthread_mutex_unlock(&g_mutex); return 0; }
static int register_callback(pid_t pid, orte_wait_fn_t callback, void *data) { registered_cb_item_t *reg_cb; pending_pids_item_t *pending; /* register the callback */ reg_cb = find_waiting_cb(pid, true); if (NULL == reg_cb) return ORTE_ERROR; if (NULL != reg_cb->callback) return ORTE_EXISTS; reg_cb->callback = callback; reg_cb->data = data; /* make sure we shouldn't trigger right now */ pending = find_pending_pid(pid, false); if (NULL != pending) { trigger_callback(reg_cb, pending); } return ORTE_SUCCESS; }
/* http://<xxx>/manual/html/section-bus-message-types.html */ static gboolean my_bus_callback(GstBus *bus, GstMessage *msg, gpointer user_data) { GstMessageType msgType; GstObject *msgSrc; gchar *msgSrcName; /* used in switch */ /* error message */ gchar *debug; GError *err; GstState oldstate, newstate, pending; /* stream status */ GstElement *owner; msgType = GST_MESSAGE_TYPE(msg); msgSrc = GST_MESSAGE_SRC(msg); msgSrcName = GST_OBJECT_NAME(msgSrc); switch (GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_EOS: g_print("GStreamer: end-of-stream\n"); pthread_mutex_lock(&g_mutex); gst_element_set_state(GST_ELEMENT(g_pipeline), GST_STATE_NULL); trigger_callback(GST_STATE_NULL); pthread_mutex_unlock(&g_mutex); break; case GST_MESSAGE_ERROR: gst_message_parse_error(msg, &err, &debug); g_free (debug); g_error("GStreamer: error: [%d] %s\n", err->code, err->message); g_error_free(err); /* TODO no sleep in callback */ pthread_mutex_lock(&g_mutex); /* setting state to null flushes pipeline */ gst_element_set_state(GST_ELEMENT(g_pipeline), GST_STATE_NULL); trigger_callback(GST_STATE_NULL); pthread_mutex_unlock(&g_mutex); break; case GST_MESSAGE_STATE_CHANGED: gst_message_parse_state_changed(msg, &oldstate, &newstate, &pending); #if 0 /* noisy */ g_print("GStreamer: %s: State change: OLD: '%s', NEW: '%s', PENDING: '%s'\n", msgSrcName, gststate_get_name(oldstate), gststate_get_name(newstate), gststate_get_name(pending)); #endif if (!strcmp(msgSrcName, g_pipeline_name)) trigger_callback(newstate); /* TODO GstState != GStreamer_state */ break; case GST_MESSAGE_WARNING: case GST_MESSAGE_INFO: /* TODO */ break; case GST_MESSAGE_APPLICATION: /* marshal information into the main thread */ case GST_MESSAGE_ASYNC_START: case GST_MESSAGE_ASYNC_DONE: case GST_MESSAGE_BUFFERING: /* caching of network streams */ case GST_MESSAGE_CLOCK_LOST: case GST_MESSAGE_CLOCK_PROVIDE: case GST_MESSAGE_ELEMENT: /* custom message, e.g. qtdemux redirect */ case GST_MESSAGE_LATENCY: case GST_MESSAGE_NEW_CLOCK: case GST_MESSAGE_REQUEST_STATE: case GST_MESSAGE_SEGMENT_DONE: case GST_MESSAGE_SEGMENT_START: case GST_MESSAGE_STATE_DIRTY: case GST_MESSAGE_STEP_DONE: case GST_MESSAGE_STRUCTURE_CHANGE: case GST_MESSAGE_TAG: /* meta data: artist, title */ /* ignore */ break; case GST_MESSAGE_DURATION: default: g_print("GStreamer: BUS_CALL %s %d\n", gst_message_type_get_name(GST_MESSAGE_TYPE(msg)), GST_MESSAGE_TYPE(msg)); break; } return 1; }