예제 #1
0
void node_attr_notify(memdb_integer db_name, struct node_attr *a,
					  memdb_integer action)
{
	int size;
	char *name;
	memdb_integer node_id = 0;
	struct subscription *s;
	struct event_info *event;
	struct list_head *which_sub = &sublist;

	if (DB_POD == db_name)
		which_sub = &pod_sublist;

	node_id = a->node->node_id;
	list_for_each_entry(s, which_sub, list) {
		if (s->event == EVENT_NODE_ATTR &&
		    s->data.attr.node_id == node_id) {
			break;
		}
	}

	size = sizeof(*event) + a->namelen + a->datalen;
	if ((event = malloc(size)) == NULL)
		return;

	event->event = EVENT_NODE_ATTR;
	event->info.attr.nodeid   = node_id;
	event->info.attr.cookie   = a->cookie;
	event->info.attr.action   = action;
	event->info.attr.namelen  = a->namelen;
	event->info.attr.datalen  = a->datalen;
	memcpy(&event->info.attr.elems[0], a->name, a->namelen);
	memcpy(&event->info.attr.elems[a->namelen], a->data, a->datalen);

	name = a->name;
	list_for_each_entry(s, which_sub, list) {
		if (s->event == EVENT_NODE_ATTR) {
			if (s->data.attr.prefix_len != 0) {
				if (strncmp(name, s->data.attr.name_prefix, s->data.attr.prefix_len) == 0 &&
					s->data.attr.node_id == node_id) {
					event_notify(s, event, size);
				}
			} else if (s->data.attr.node_id != 0) {
				if (s->data.attr.node_id == node_id)
					event_notify(s, event, size);
			} else {
				event_notify(s, event, size);
			}
		}
	}

	free(event);
}
예제 #2
0
파일: event.cpp 프로젝트: mondhs/espeak
static int event_delete(espeak_EVENT* event)
{
ENTER("event_delete");

	event_display(event);

	if(event==NULL)
	{
		return 0;
	}

	switch(event->type)
	{
	case espeakEVENT_MSG_TERMINATED:
		event_notify(event);
		break;

	case espeakEVENT_MARK:
	case espeakEVENT_PLAY:
		if(event->id.name)
		{
			free((void*)(event->id.name));
		}
		break;

	default:
		break;
	}

	free(event);
	return 1;
}
예제 #3
0
파일: sched_wiki2.c 프로젝트: A1ve5/slurm
extern uint32_t
slurm_sched_p_initial_priority( uint32_t last_prio,
				     struct job_record *job_ptr )
{
	(void) event_notify(1234, "Job submit");

	if ((job_ptr->job_id >= first_job_id) && exclude_part_ptr[0]) {
		/* Interactive job (initiated by srun) in partition
		 * excluded from Moab scheduling */
		int i;
		static int exclude_prio = 100000000;
		for (i=0; i<EXC_PART_CNT; i++) {
			if (exclude_part_ptr[i] == NULL)
				break;
			if (exclude_part_ptr[i] == job_ptr->part_ptr) {
				debug("Scheduiling job %u directly (no Moab)",
					job_ptr->job_id);
				return (exclude_prio--);
			}
		}
		return 0;
	}

	if (init_prio_mode == PRIO_DECREMENT)
		return priority_g_set(last_prio, job_ptr);

	return 0;
}
예제 #4
0
static void
sched_callback(event_handle_t handle,
	       event_notification_t notification,
	       void *data)
{
	if (! event_notify(bosshandle, notification))
		error("Failed to deliver scheduled notification!");
}
예제 #5
0
파일: main.c 프로젝트: cjxgm/learning
static void sleep_thread(char* msg)
{
	Event* ev = event(msg);
	event_system_source(evsys, ev);
	while (1) {
		printf("pre-notify \"%s\"\n", msg);
		event_notify(ev);
		printf("pos-notify \"%s\"\n", msg);
		sleep(rand()&0b11);
	}
}
예제 #6
0
파일: main.c 프로젝트: cjxgm/learning
static void timer_thread(int duration)
{
	char msg[128];
	sprintf(msg, "\e[0;33mtimer \e[1;35m%d\e[0;35mms\e[0;33m timeout\e[0m", duration);
	Event* ev = event(msg);
	event_system_source(evsys, ev);
	while (1) {
		clock_t start = clock();
		while (clock()-start < duration*CLOCKS_PER_SEC/1000) {}
		event_notify(ev);
	}
}
예제 #7
0
int MsgStorage::msg_delete(string domain, string user, string msg_name) { 
  // TODO: check the directory lock
  string path = msg_dir + "/" + domain + "/" + user + "/" + msg_name;
  if (unlink(path.c_str())) {
      ERROR("cannot unlink '%s': %s\n", 
	    path.c_str(),strerror(errno));
      return MSG_EMSGNOTFOUND;
  }

  event_notify(domain,user,"msg_delete");

  return MSG_OK;
}
예제 #8
0
파일: handler.c 프로젝트: fenollp/kaneton
void			architecture_handler_exception(t_uint32	n,
						       t_uint32	code)
{
  i_event		id;
  o_event*		o;

  /*
   * 1)
   */

  assert(architecture_context_locate() == STATUS_OK);

  /*
   * 2)
   */

  id = (i_event)(ARCHITECTURE_IDT_EXCEPTION_BASE + n);

  if (event_exist(id) != TRUE)
    {
      architecture_handler_spurious((t_uint32)id);

      return;
    }

  /*
   * 3)
   */

  assert(event_get(id, &o) == STATUS_OK);

  /*
   * 4)
   */

  _architecture.error = code;

  /*
   * 5)
   */

  assert(event_notify(id) == STATUS_OK);

  /*
   * 6)
   */

  _architecture.error = 0;
}
예제 #9
0
파일: handler.c 프로젝트: fenollp/kaneton
void			architecture_handler_irq(t_uint32	n)
{
  i_event		id;
  o_event*		o;

  /*
   * 1)
   */

  assert(architecture_context_locate() == STATUS_OK);

  /*
   * 2)
   */

  id = (i_event)(ARCHITECTURE_IDT_IRQ_BASE + n);

  if (event_exist(id) != TRUE)
    {
      architecture_handler_spurious((t_uint32)id);

      return;
    }

  /*
   * 3)
   */

  assert(event_get(id, &o) == STATUS_OK);

  /*
   * 4)
   */

  assert(event_notify(id) == STATUS_OK);

  /*
   * 5)
   */

  platform_pic_acknowledge(n);
}
예제 #10
0
void node_create_notify(memdb_integer db_name, struct node *n)
{
	struct subscription *s;
	struct event_info event;
	struct list_head *which_sub = &sublist;

	if (DB_POD == db_name)
		which_sub = &pod_sublist;

	event.event = EVENT_NODE_CREATE;
	event.nnodeid = n->node_id;
	event.nparent = n->parent != NULL ? n->parent->node_id : 0UL;
	event.ntype = n->type;

	list_for_each_entry(s, which_sub, list) {
		if (s->event == EVENT_NODE_CREATE &&
		    n->type >= s->data.node.type_min &&
		    n->type <= s->data.node.type_max)
			event_notify(s, &event, sizeof(event));
	}
}
예제 #11
0
파일: ble_ans_c.c 프로젝트: IOIOI/nRF51
/**@brief Function for handling of BLE stack events.
 */
void ble_ans_c_on_ble_evt(ble_ans_c_t * p_ans, const ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GATTC_EVT_HVX:
            event_notify(p_ans, p_ble_evt);
            break;

        case BLE_GATTC_EVT_WRITE_RSP:
            event_write_rsp(p_ans, p_ble_evt);
            break;

        case BLE_GATTC_EVT_READ_RSP:
            event_read_rsp(p_ans, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            event_disconnect(p_ans, p_ble_evt);
            break;
    }
}
예제 #12
0
int MsgStorage::msg_new(string domain, string user, 
			string msg_name, FILE* data) {

  string path = msg_dir+ "/" + domain + "/" ;
  int status = mkdir(path.c_str(), 
		     S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  if (status && (errno != EEXIST)) {
    ERROR("creating '%s': %s\n", 
	  path.c_str(),strerror(errno));
    return MSG_EUSRNOTFOUND;
  }

  path = msg_dir+ "/" + domain + "/" + user + "/";
  status = mkdir(path.c_str(), 
		     S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  if (status && (errno != EEXIST)) {
    ERROR("creating '%s': %s\n", 
	  path.c_str(),strerror(errno));
    return MSG_EUSRNOTFOUND;
  }

  DBG("creating '%s'\n", (path + msg_name).c_str());

  FILE* fp = fopen((path + msg_name).c_str(), "wb");
  if (!fp) {
    ERROR("creating '%s': %s\n", 
	  (path + msg_name).c_str(),strerror(errno));
    return MSG_ESTORAGE;
  }

  if (data)
    filecopy(data, fp);
  fclose(fp);

  event_notify(domain,user,"msg_new");

  return MSG_OK;
}
예제 #13
0
int pnet_rx_thread_add(struct pnet_pack *pack) {
	uint32_t prio;

	prio = pack->priority;

	if (pack->stat.last_sync != (clock_t)-1) {
		/* We are not in differed irq handler */
		if ((thread_self() != pnet_rx_threads[prio])) {
			/* If we will switched to thread with higher priority, than calculate running time in current thread
			 * and initialize start timestamp in new thread */
			pack->stat.running_time += thread_get_running_time(thread_self()) - pack->stat.last_sync;
			pack->stat.last_sync = thread_get_running_time(pnet_rx_threads[prio]);
		}
	} else {
		/* We are in differed irq handler */
		pack->stat.last_sync = thread_get_running_time(pnet_rx_threads[prio]);
	}

	ring_buff_enqueue(&pack_storage[prio].buff, &pack, 1);
	event_notify(&pack_storage[prio].event);

	return 0;
}
예제 #14
0
/*
 * Handle incoming events from the remote server. 
 */
static void
callback(event_handle_t handle, event_notification_t notification, void *data)
{
	char		eventtype[TBDB_FLEN_EVEVENTTYPE];
	char		objecttype[TBDB_FLEN_EVOBJTYPE];
	char		objectname[TBDB_FLEN_EVOBJNAME];

	if (debug) {
		event_notification_get_eventtype(handle,
				notification, eventtype, sizeof(eventtype));
		event_notification_get_objtype(handle,
				notification, objecttype, sizeof(objecttype));
		event_notification_get_objname(handle,
				notification, objectname, sizeof(objectname));

		info("%s %s %s\n", eventtype, objecttype, objectname);
	}
	/*
	 * Resend the notification to the local server.
	 */
	if (! event_notify(localhandle, notification))
		error("Failed to deliver notification!");
}
예제 #15
0
파일: msg.c 프로젝트: bingzhang/slurm
/*****************************************************************************\
 * spawn message hander thread
\*****************************************************************************/
extern int spawn_msg_thread(void)
{
	pthread_attr_t thread_attr_msg;

	pthread_mutex_lock( &thread_flag_mutex );
	if (thread_running) {
		error("Wiki thread already running, not starting another");
		pthread_mutex_unlock(&thread_flag_mutex);
		return SLURM_ERROR;
	}

	parse_wiki_config();
	slurm_attr_init(&thread_attr_msg);
	if (pthread_create(&msg_thread_id, &thread_attr_msg,
			_msg_thread, NULL))
		fatal("pthread_create %m");

	(void) event_notify(1235, "Slurm startup");
	slurm_attr_destroy(&thread_attr_msg);
	thread_running = true;
	pthread_mutex_unlock(&thread_flag_mutex);
	return SLURM_SUCCESS;
}
예제 #16
0
파일: handler.c 프로젝트: fenollp/kaneton
void			architecture_handler_syscall(t_uint32	n)
{
  i_event		id;
  o_event*		o;

  /*
   * 1)
   */

  assert(architecture_context_locate() == STATUS_OK);

  /*
   * 2)
   */

  id = (i_event)(ARCHITECTURE_IDT_SYSCALL_BASE + n);

  if (event_exist(id) != TRUE)
    {
      architecture_handler_spurious((t_uint32)id);

      return;
    }

  /*
   * 3)
   */

  assert(event_get(id, &o) == STATUS_OK);

  /*
   * 4)
   */

  assert(event_notify(id) == STATUS_OK);
}
예제 #17
0
int MsgStorage::msg_markread(string domain, string user, string msg_name) { 
  string path = msg_dir + "/" +  domain + "/" + user + "/" + msg_name;

  struct stat e_stat;
  if (stat(path.c_str(), &e_stat)) {
    ERROR("cannot stat '%s': %s\n", 
	  path.c_str(),strerror(errno));
    return MSG_EMSGNOTFOUND;
  }

  struct utimbuf buf;
  buf.actime = e_stat.st_mtime+1;
  buf.modtime = e_stat.st_mtime;

  if (utime(path.c_str(), &buf)) {
    ERROR("cannot utime '%s': %s\n", 
	  path.c_str(),strerror(errno));
    return MSG_EREADERROR;
  }

  event_notify(domain,user,"msg_markread");

  return MSG_OK;
}
예제 #18
0
/**@brief Function for handling of BLE stack events.
 */
void ble_ans_c_on_ble_evt(ble_ans_c_t * p_ans, const ble_evt_t * p_ble_evt)
{
    uint16_t event = p_ble_evt->header.evt_id;

    switch (m_client_state)
    {
        case STATE_UNINITIALIZED:
            // Initialization is handle in special case, thus if we enter here, it means that an
            // event is received even though we are not initialized --> ignore.
            break;

        case STATE_IDLE:
            if (event == BLE_GAP_EVT_CONNECTED)
            {
                event_connect(p_ans, p_ble_evt);
            }
            break;

        case STATE_WAITING_ENC:
            if ((event == BLE_GAP_EVT_AUTH_STATUS) || (event == BLE_GAP_EVT_SEC_INFO_REQUEST))
            {
                event_encrypted_link(p_ans, p_ble_evt);
            }
            else if (event == BLE_GAP_EVT_DISCONNECTED)
            {
                event_disconnect(p_ans);
            }
            break;

        case STATE_DISC_SERV:
            if (event == BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP)
            {
                event_discover_rsp(p_ans, p_ble_evt);
            }
            else if (event == BLE_GAP_EVT_DISCONNECTED)
            {
                event_disconnect(p_ans);
            }
            break;

        case STATE_DISC_CHAR:
            if (event == BLE_GATTC_EVT_CHAR_DISC_RSP)
            {
                event_characteristic_rsp(p_ans, p_ble_evt);
            }
            else if (event == BLE_GAP_EVT_DISCONNECTED)
            {
                event_disconnect(p_ans);
            }
            break;

        case STATE_DISC_DESC:
            if (event == BLE_GATTC_EVT_DESC_DISC_RSP)
            {
                event_descriptor_rsp(p_ans, p_ble_evt);
            }
            else if (event == BLE_GAP_EVT_DISCONNECTED)
            {
                event_disconnect(p_ans);
            }
            break;

        case STATE_RUNNING:
            if (event == BLE_GATTC_EVT_HVX)
            {
                event_notify(p_ans, p_ble_evt);
            }
            else if (event == BLE_GATTC_EVT_READ_RSP)
            {
                event_read_rsp(p_ans, p_ble_evt);
            }
            else if (event == BLE_GATTC_EVT_WRITE_RSP)
            {
                event_write_rsp(p_ans, p_ble_evt);
            }
            else if (event == BLE_GAP_EVT_DISCONNECTED)
            {
                event_disconnect(p_ans);
            }
            else
            {
                // Do nothing, event not handled in this state.
            }
            break;

        case STATE_RUNNING_NOT_DISCOVERED:
            if (event == BLE_GAP_EVT_DISCONNECTED)
            {
                event_disconnect(p_ans);
            }
            break;

        default:
            event_disconnect(p_ans);
            break;
    }
}
예제 #19
0
파일: sched_wiki2.c 프로젝트: A1ve5/slurm
extern int slurm_sched_p_schedule( void )
{
	(void) event_notify(1234, "Requested by Slurm");
	return SLURM_SUCCESS;
}
예제 #20
0
파일: sched_wiki2.c 프로젝트: A1ve5/slurm
void slurm_sched_p_partition_change( void )
{
	(void) event_notify(1235, "Partition change");
}
예제 #21
0
static void *polling_thread(void *p)
{
	(void)p; // unused

	while (1) {
		int a_stop_is_required = 0;

		(void)pthread_mutex_lock(&my_mutex);
		my_event_is_running = 0;

		while (my_start_is_required == 0) {
			while ((pthread_cond_wait(&my_cond_start_is_required, &my_mutex) == -1) && errno == EINTR)
				continue; // Restart when interrupted by handler
		}

		my_event_is_running = 1;
		a_stop_is_required = 0;
		my_start_is_required = 0;

		pthread_mutex_unlock(&my_mutex);

		// In this loop, my_event_is_running = 1
		while (head && (a_stop_is_required == 0)) {
			espeak_EVENT *event = (espeak_EVENT *)(head->data);
			assert(event);

			if (my_callback) {
				event_notify(event);
				// the user_data (and the type) are cleaned to be sure
				// that MSG_TERMINATED is called twice (at delete time too).
				event->type = espeakEVENT_LIST_TERMINATED;
				event->user_data = NULL;
			}

			(void)pthread_mutex_lock(&my_mutex);
			event_delete((espeak_EVENT *)pop());
			a_stop_is_required = my_stop_is_required;
			if (a_stop_is_required > 0)
				my_stop_is_required = 0;

			(void)pthread_mutex_unlock(&my_mutex);
		}

		(void)pthread_mutex_lock(&my_mutex);

		my_event_is_running = 0;

		if (a_stop_is_required == 0) {
			a_stop_is_required = my_stop_is_required;
			if (a_stop_is_required > 0)
				my_stop_is_required = 0;
		}

		(void)pthread_mutex_unlock(&my_mutex);

		if (a_stop_is_required > 0) {
			// no mutex required since the stop command is synchronous
			// and waiting for my_cond_stop_is_acknowledged
			init();

			// acknowledge the stop request
			(void)pthread_mutex_lock(&my_mutex);
			my_stop_is_acknowledged = 1;
			(void)pthread_cond_signal(&my_cond_stop_is_acknowledged);
			(void)pthread_mutex_unlock(&my_mutex);
		}
	}

	return NULL;
}
예제 #22
0
파일: event.cpp 프로젝트: mondhs/espeak
static void* polling_thread(void*)
{
ENTER("polling_thread");

	while(1)
	{
		int a_stop_is_required=0;

		SHOW_TIME("polling_thread > locking\n");
		int a_status = pthread_mutex_lock(&my_mutex);
		SHOW_TIME("polling_thread > locked (my_event_is_running = 0)\n");
		my_event_is_running = 0;
		pthread_mutex_unlock(&my_mutex);
		SHOW_TIME("polling_thread > unlocked\n");

		SHOW_TIME("polling_thread > wait for my_sem_start_is_required\n");

		while ((sem_wait(&my_sem_start_is_required) == -1) && errno == EINTR)
		{
			continue; // Restart when interrupted by handler
		}

		SHOW_TIME("polling_thread > get my_sem_start_is_required\n");

		a_status = pthread_mutex_lock(&my_mutex);
		SHOW_TIME("polling_thread > locked (my_event_is_running = 1)\n");
		my_event_is_running = 1;
		pthread_mutex_unlock(&my_mutex);
		SHOW_TIME("polling_thread > unlocked\n");

		a_stop_is_required=0;
		a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required);  // NOTE: may set a_stop_is_required to -1
		if ((a_status==0) && (a_stop_is_required > 0))
		{
			SHOW("polling_thread > stop required (%d)\n", __LINE__);
			while(0 == sem_trywait(&my_sem_stop_is_required))
			{
			};
		}
		else
		{
			a_stop_is_required=0;
		}

		// In this loop, my_event_is_running = 1
		while (head && (a_stop_is_required <= 0))
		{
			SHOW_TIME("polling_thread > check head\n");
			while(0 == sem_trywait(&my_sem_start_is_required))
			{
			};
	
			espeak_EVENT* event = (espeak_EVENT*)(head->data);
			assert(event);
	
			uint32_t time_in_ms = 0;
	
			int err = get_remaining_time((uint32_t)event->sample, 
							&time_in_ms, 
							&a_stop_is_required);
			if (a_stop_is_required > 0)
			{
				break;
			}
			else if (err != 0)
			{ 
				// No available time: the event is deleted.
				SHOW("polling_thread > %s\n","audio device down");
				a_status = pthread_mutex_lock(&my_mutex);
				SHOW_TIME("polling_thread > locked\n");
				event_delete( (espeak_EVENT*)pop());
				a_status = pthread_mutex_unlock(&my_mutex);
				SHOW_TIME("polling_thread > unlocked\n");
			}
			else if (time_in_ms==0)
			{ // the event is already reached.
				if (my_callback)
				{
					event_notify(event);
					// the user_data (and the type) are cleaned to be sure 
					// that MSG_TERMINATED is called twice (at delete time too).
					event->type=espeakEVENT_LIST_TERMINATED;
					event->user_data=NULL;
				}
	
				a_status = pthread_mutex_lock(&my_mutex);
				SHOW_TIME("polling_thread > locked\n");
				event_delete( (espeak_EVENT*)pop());
				a_status = pthread_mutex_unlock(&my_mutex);
				SHOW_TIME("polling_thread > unlocked\n");
			
				a_stop_is_required=0;
				a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required);
	
				if ((a_status==0) && (a_stop_is_required > 0))
				{
					SHOW("polling_thread > stop required (%d)\n", __LINE__);
					while(0 == sem_trywait(&my_sem_stop_is_required))
					{
					};
				}
				else
				{
					a_stop_is_required=0;
				}
			}
			else
			{ // The event will be notified soon: sleep until timeout or stop request
				a_stop_is_required = sleep_until_timeout_or_stop_request(time_in_ms);
			}
		}
	
		a_status = pthread_mutex_lock(&my_mutex);
		SHOW_TIME("polling_thread > locked\n");
	
		SHOW_TIME("polling_thread > my_event_is_running = 0\n");
		my_event_is_running = 0;
	
		if(a_stop_is_required <= 0)
		{
			a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required);
			if ((a_status==0) && (a_stop_is_required > 0))
			{
				SHOW("polling_thread > stop required (%d)\n", __LINE__);
				while(0 == sem_trywait(&my_sem_stop_is_required))
				{
				};
			}
			else
			{
				a_stop_is_required=0;
			}
		}

		a_status = pthread_mutex_unlock(&my_mutex);
		SHOW_TIME("polling_thread > unlocked\n");

		if (a_stop_is_required > 0)
		{ 
			SHOW("polling_thread > %s\n","stop required!");
			// no mutex required since the stop command is synchronous
			// and waiting for my_sem_stop_is_acknowledged
			init();

			// acknowledge the stop request
			SHOW_TIME("polling_thread > post my_sem_stop_is_acknowledged\n");
			a_status = sem_post(&my_sem_stop_is_acknowledged);
		}
	}

	return NULL;
}
예제 #23
0
파일: sched_wiki2.c 프로젝트: A1ve5/slurm
int slurm_sched_p_reconfig( void )
{
	int rc = parse_wiki_config();
	(void) event_notify(1235, "Partition change");
	return rc;
}