Exemple #1
0
int log_putc(int c)
{
	if(last_update.trigger_value == 0)
		last_update = register_timer(LOG_TIMEOUT);

	if(log_buf && buf_size)
	{
		log_buf[buf_ptr++] = c;
		if(buf_ptr >= buf_size)
		{
			if(log_fp && log_fp->fflush_cb)
			{
				log_fp->fflush_cb(log_fp);
				last_update = register_timer(LOG_TIMEOUT);
			}
			buf_ptr = 0;
		}
		return 0;
	}
	else if(log_fp)
	{
		// Disable output to the log for the write
		rpi_boot_output_state state = output_get_state();
		output_disable_log();

		// Write one character
		fwrite(&c, 1, 1, log_fp);

		// Restore saved output state
		output_restore_state(state);
		return 0;
	}
	return EOF;
}
Exemple #2
0
static int mod_init(void)
{
	LM_INFO("Call Center module - initializing\n");

	init_db_url( db_url , 0 /*cannot be null*/);
	init_db_url( acc_db_url , 0 /*cannot be null*/);
	b2b_scenario.len = strlen(b2b_scenario.s);

	/* Load B2BUA API */
	if (load_b2b_logic_api( &b2b_api) != 0) {
		LM_ERR("Can't load B2B-UA hooks, missing 'b2b_logic' module ?\n");
		return -1;
	}

	if (register_timer( "cc_agents", cc_timer_agents, NULL, 1)<0) {
		LM_ERR("failed to register agents timer function\n");
		return -1;
	}

	if (register_timer( "cc_cleanup", cc_timer_cleanup, NULL, 5)<0) {
		LM_ERR("failed to register cleaup timer function\n");
		return -1;
	}

	/* main CC data */
	data = init_cc_data();
	if (data==0) {
		LM_CRIT("failed to get shm mem for data\n");
		return -1;
	}

	/* init and open DB connection */
	if (init_cc_db( &db_url )!=0) {
		LM_ERR("failed to initialize the DB support\n");
		return -1;
	}
	if (init_cc_acc_db( &acc_db_url )!=0) {
		LM_ERR("failed to initialize the acc DB support\n");
		return -1;
	}

	/* load data */
	if ( cc_load_db_data( data )!=0 ) {
		LM_CRIT("failed to load callcenter data\n");
		return -1;
	}
	clean_cc_old_data(data);

	/* restore calls */
	if ( cc_db_restore_calls( data )!=0 ) {
		LM_CRIT("failed to load callcenter data\n");
		return -1;
	}

	/* close DB connection */
	cc_close_db();

	return 0;
}
Exemple #3
0
/**
 * init module function
 */
static int mod_init(void)
{
	stm_timer_t *it;
	if(_stm_list==NULL)
		return 0;

	/* init faked sip msg */
	if(faked_msg_init()<0)
	{
		LM_ERR("failed to init timer local sip msg\n");
		return -1;
	}

	/* register timers */
	it = _stm_list;
	while(it)
	{
		if(it->mode==0)
		{
			if(register_timer(stm_timer_exec, (void*)it, it->interval)<0)
			{
				LM_ERR("failed to register timer function\n");
				return -1;
			}
		} else {
			register_basic_timers(1);
		}
		it = it->next;
	}

	return 0;
}
Exemple #4
0
static int mod_init(void)
{
	LM_INFO("initializing SMPP protocol\n");

	db_url.len = strlen(db_url.s);
	smpp_outbound_uri.len = strlen(smpp_outbound_uri.s);

	if (smpp_db_init(&db_url) < 0)
		return -1;

	if (smpp_sessions_init() < 0)
		return -1;

	smpp_db_close();

	if (register_timer("enquire-link-timer", enquire_link, NULL, 5,
			TIMER_FLAG_DELAY_ON_DELAY)<0 )
		return -1;

	/* load the TM API */
	if (load_tm_api(&tmb)!=0) {
		LM_ERR("can't load TM API\n");
		return -1;
	}


	return 0;
}
Exemple #5
0
void get_cpu_info(unsigned long arg)
{
	unsigned int i;
	unsigned int frequency;
	cputime64_t curr_idle_time, curr_wall_time;
	unsigned int delta_wall_time, delta_idle_time;
	unsigned int cpu_load;
	
	struct cpu_monitor_info_s *pdata = (struct cpu_monitor_info_s *)arg;

	/* CPU frequency */
	frequency = cpufreq_quick_get(0);
	printk("[Monitor] cpu frequency: %u\n", frequency);

	for(i=0; i<NUM_CPUS; ++i)
	{
		/* CPU load */
		curr_idle_time = get_cpu_idle_time_us(i, &curr_wall_time);
		delta_wall_time = (unsigned int) cputime64_sub(curr_wall_time, 
				pdata->cpu_info[i].prev_cpu_wall);
		pdata->cpu_info[i].prev_cpu_wall = curr_wall_time;

		delta_idle_time = (unsigned int) cputime64_sub(curr_idle_time, 
				pdata->cpu_info[i].prev_cpu_idle);
		pdata->cpu_info[i].prev_cpu_idle = curr_idle_time;

		cpu_load = 100*(delta_wall_time - delta_idle_time)/delta_wall_time;
		if(cpu_load>100)	cpu_load=0;
		printk("[Monitor] cpu %u load: %u\n", i, cpu_load);
	}
	
	if(g_counter<10)
		register_timer(pdata, TIME_STEP);
}
Exemple #6
0
int initialize_kill(void)
{
	/* if disabled ... */
	if (time_to_kill == 0)
		return 0;

	if (register_timer("exec_kill", timer_routine, NULL /* param */,
	    1 /* period */, TIMER_FLAG_SKIP_ON_DELAY) < 0) {
		LM_ERR("no exec timer registered\n");
		return -1;
	}

	kill_list = shm_malloc(sizeof *kill_list);
	if (!kill_list) {
		LM_ERR("no more shm!\n");
		return -1;
	}

	kill_list->first_tl.next_tl = &kill_list->last_tl;
	kill_list->last_tl.prev_tl  = &kill_list->first_tl;
	kill_list->first_tl.prev_tl =
	kill_list->last_tl.next_tl  = NULL;

	kill_list->last_tl.time_out = -1;

	kill_lock = lock_alloc();
	if (!kill_lock) {
		LM_ERR("no shm mem for mutex\n");
		return -1;
	}
	lock_init(kill_lock);

	LM_DBG("kill initialized\n");
	return 0;
}
static int
mod_init(void)
{
    bind_usrloc_t ul_bind_usrloc;

    if (natpingInterval > 0) {
        ul_bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
        if (!ul_bind_usrloc) {
            LOG(L_ERR, "error: mediaproxy/mod_init(): can't find the usrloc "
                "module. Check if usrloc.so is loaded.\n");
            return -1;
        }

        if (ul_bind_usrloc(&userLocation) < 0) {
            LOG(L_ERR, "error: mediaproxy/mod_init(): can't access the usrloc module.\n");
            return -1;
        }

        register_timer(pingClients, NULL, natpingInterval);
    }

    checkAsymmetricFile(&sipAsymmetrics);
    checkAsymmetricFile(&rtpAsymmetrics);

    // children won't benefit from this. figure another way
    //register_timer(checkAsymmetricFiles, NULL, 5);

    return 0;
}
/**
 * init module function
 */
static int mod_init(void)
{
	load_tm_f  load_tm;

	DBG("MSILO: initializing ...\n");

	/* binding to mysql module  */
	if (bind_dbmod())
	{
		DBG("MSILO: ERROR: Database module not found\n");
		return -1;
	}

	/* import the TM auto-loading function */
	if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) {
		LOG(L_ERR, "ERROR: msilo: mod_init: can't import load_tm\n");
		return -1;
	}
	/* let the auto-loading function load all TM stuff */
	if (load_tm( &tmb )==-1)
		return -1;

	ml = msg_list_init();
	if(!ml)
	{
		DBG("ERROR: msilo: mod_init: can't initialize msg list\n");
		return -1;
	}
	register_timer( m_clean_silo, 0, check_time);

	reg_addr.s = registrar;
	reg_addr.len = (registrar)?strlen(registrar):0;

	return 0;
}
Exemple #9
0
/*
 * Module initialization function
 */
static int mod_init(void)
{
	DBG("usrloc - initializing\n");

	     /* Register cache timer */
	register_timer(timer, 0, timer_interval);

	     /* Initialize fifo interface */
	if (init_ul_fifo()<0) {
		LOG(L_ERR, "ERROR: usrloc/fifo initialization failed\n");
		return -1;
	}

	     /* Shall we use database ? */
	if (db_mode != NO_DB) { /* Yes */
		if (bind_dbmod() < 0) { /* Find database module */
			LOG(L_ERR, "mod_init(): Can't bind database module\n");
			return -1;
		}
		
		     /* Open database connection in parent */
		db = db_init(db_url);
		if (!db) {
			LOG(L_ERR, "mod_init(): Error while connecting database\n");
			return -1;
		} else {
			LOG(L_INFO, "mod_init(): Database connection opened successfuly\n");
		}
	}

	return 0;
}
Exemple #10
0
void register_functions( lua_State* L, gwlua_t* state )
{
  static const luaL_Reg statics[] =
  {
    { "playsound",     l_playsound },
    { "stopsounds",    l_stopsounds },
    { "randomize",     l_randomize },
    { "random",        l_random },
    { "round",         l_round },
    { "now",           l_now },
    { "splittime",     l_splittime },
    { "inttostr",      l_inttostr },
    { "loadvalue",     l_loadvalue },
    { "savevalue",     l_savevalue },
    { "setbackground", l_setbackground },
    { "setzoom",       l_setzoom },
    { "inputstate",    l_inputstate },
    { "loadbin",       l_loadbin },
    { "loadbs",        l_loadbs },
    { NULL, NULL }
  };
  
  lua_newtable( L );
  
  register_image( L, state );
  register_sound( L, state );
  register_timer( L, state );
  
  lua_pushlightuserdata( L, (void*)state );
  luaL_setfuncs( L, statics, 1 );
  
  // module
  
  if ( luaL_loadbufferx( L, (const char*)gwlua_lua_system_lua, gwlua_lua_system_lua_len, "system.lua", "t" ) != LUA_OK )
  {
    lua_error( L );
    return;
  }
  
  // module chunk
  
  lua_call( L, 0, 1 );
  
  // module function
  
  lua_pushvalue( L, -2 );
  
  // module function module
  
  lua_call( L, 1, 0 );
  
  // module
  
  lua_setglobal( L, "system" );
  
  // --
}
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  render_layer = layer_create(bounds);
  layer_set_update_proc(render_layer, update_display);
  layer_add_child(window_layer, render_layer);
  register_timer(NULL);
}
int repl_prof_init(void)
{
	int index;

	if (!repl_prof_dests_nr)
		return 0;

	if (repl_prof_utimer < 0) {
		LM_ERR("negative replicate timer for profiles %d\n", repl_prof_utimer);
		return -1;
	}
	if (repl_prof_timer_check < 0) {
		LM_ERR("negative replicate timer for profiles check %d\n",
				repl_prof_timer_check);
		return -1;
	}

	if (repl_prof_timer_expire < 0) {
		LM_ERR("negative replicate expire timer for profiles %d\n",
				repl_prof_timer_expire);
		return -1;
	}

	if (repl_prof_buffer_th < 0) {
		LM_ERR("negative replicate buffer threshold for profiles %d\n",
				repl_prof_buffer_th);
		return -1;
	}

	if (register_utimer("dialog-repl-profiles-utimer", repl_prof_utimer_f, NULL,
			repl_prof_utimer * 1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) {
		LM_ERR("failed to register profiles utimer\n");
		return -1;
	}
	if (register_timer("dialog-repl-profiles-timer", repl_prof_timer_f, NULL,
			repl_prof_timer_check, TIMER_FLAG_DELAY_ON_DELAY) < 0) {
		LM_ERR("failed to register profiles utimer\n");
		return -1;
	}

	if (repl_prof_buffer_th > (BUF_SIZE * 0.9)) {
		LM_WARN("Buffer size too big %d - profiles information might get lost",
				repl_prof_buffer_th);
		return -1;
	}

	/* alocate the last_message counter in shared memory */
	for (index = 0; index < repl_prof_dests_nr; index++) {
		repl_prof_dests[index].last_msg = shm_malloc(sizeof(time_t));
		if (!repl_prof_dests[index].last_msg) {
			LM_ERR("OOM shm\n");
			return -1;
		}
	}

	return 0;
}
Exemple #13
0
/**
 * init module function
 */
static int mod_init(void)
{
	bind_xcap_t bind_xcap;
	xcap_api_t xcap_api;

        /* load XCAP API */
        bind_xcap = (bind_xcap_t)find_export("bind_xcap", 1, 0);
        if (!bind_xcap)
        {
                LM_ERR("Can't bind xcap\n");
                return -1;
        }

        if (bind_xcap(&xcap_api) < 0)
        {
                LM_ERR("Can't bind xcap\n");
                return -1;
        }
        xcap_db_url = xcap_api.db_url;
        xcap_db_table = xcap_api.xcap_table;

	/* binding to mysql module  */
	if (db_bind_mod(&xcap_db_url, &xcap_dbf))
	{
		LM_ERR("Database module not found\n");
		return -1;
	}

	if (!DB_CAPABILITY(xcap_dbf, DB_CAP_ALL)) {
		LM_ERR("Database module does not implement all functions"
				" needed by the module\n");
		return -1;
	}

	xcap_db = xcap_dbf.init(&xcap_db_url);
	if (!xcap_db)
	{
		LM_ERR("while connecting to database\n");
		return -1;
	}

	curl_global_init(CURL_GLOBAL_ALL);

	if(periodical_query)
	{
		register_timer("xcapc-update", query_xcap_update, 0,
			query_period, TIMER_FLAG_DELAY_ON_DELAY);
	}

	if(xcap_db)
		xcap_dbf.close(xcap_db);
	xcap_db = NULL;

	return 0;
}
Exemple #14
0
/**
 * init module function
 */
static int mod_init(void)
{
	if(register_mi_mod(exports.name, mi_cmds)!=0)
	{
		LM_ERR("failed to register MI commands\n");
		return -1;
	}
	if(htable_init_rpc()!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	if(ht_init_tables()!=0)
		return -1;
	ht_db_init_params();

	if(ht_db_url.len>0)
	{
		if(ht_db_init_con()!=0)
			return -1;
		if(ht_db_open_con()!=0)
			return -1;
		if(ht_db_load_tables()!=0)
		{
			ht_db_close_con();
			return -1;
		}
		ht_db_close_con();
	}
	if(ht_has_autoexpire())
	{
		LM_DBG("starting auto-expire timer\n");
		if(ht_timer_interval<=0)
			ht_timer_interval = 20;
		if(ht_timer_procs<=0) {
			if(register_timer(ht_timer, 0, ht_timer_interval)<0)
			{
				LM_ERR("failed to register timer function\n");
				return -1;
			}
		} else {
			register_sync_timers(ht_timer_procs);
		}
	}

	if (ht_enable_dmq>0 && ht_dmq_initialize()!=0) {
		LM_ERR("failed to initialize dmq integration\n");
		return -1;
	}

	ht_iterator_init();

	return 0;
}
Exemple #15
0
/** Module init function */
static int mod_init(void)
{
	if(load_uac_auth_api(&uac_auth_api)<0){
		LM_ERR("Failed to load uac_auth api\n");
		return -1;
	}

	/* load all TM stuff */
	if(load_tm_api(&tmb)==-1) {
		LM_ERR("can't load tm functions\n");
		return -1;
	}

	if(default_expires<15){
		LM_ERR("default_expires to short: [%d]<15\n", default_expires);
		return -1;
	}
	if(timer_interval<10){
		LM_ERR("timer_interval to short: [%d]<10\n", timer_interval);
		return -1;
	}
	if(reg_hsize<1 || reg_hsize>20) {
		LM_ERR("Wrong hash size: 20<[%d]<1\n", reg_hsize);
	}
	reg_hsize = 1<<reg_hsize;

	if(init_reg_htable()<0) {
		LM_ERR("Failed to initialize registrant hash table\n");
		return -1;
	}

	reg_table_name.len = strlen(reg_table_name.s);
	registrar_column.len = strlen(registrar_column.s);
	proxy_column.len = strlen(proxy_column.s);
	aor_column.len = strlen(aor_column.s);
	third_party_registrant_column.len =
		strlen(third_party_registrant_column.s);
	username_column.len = strlen(username_column.s);
	password_column.len = strlen(password_column.s);
	binding_URI_column.len = strlen(binding_URI_column.s);
	binding_params_column.len = strlen(binding_params_column.s);
	expiry_column.len = strlen(expiry_column.s);
	forced_socket_column.len = strlen(forced_socket_column.s);
	init_db_url(db_url , 0 /*cannot be null*/);
	if (init_reg_db(&db_url) != 0) {
		LM_ERR("failed to initialize the DB support\n");
		return -1;
	}

	register_timer("uac_reg_check", timer_check, 0,
					timer_interval/reg_hsize);

	return 0;
}
Exemple #16
0
int repl_prof_init(void)
{
	if (!profile_replicate_cluster && !accept_repl_profiles)
		return 0;

	if (repl_prof_timer_check < 0) {
		LM_ERR("negative replicate timer for profiles check %d\n",
			repl_prof_timer_check);
		return -1;
	}

	if (repl_prof_timer_expire < 0) {
		LM_ERR("negative replicate expire timer for profiles %d\n",
			repl_prof_timer_expire);
		return -1;
	}

	if (register_timer("dialog-repl-profiles-timer", repl_prof_timer_f, NULL,
		repl_prof_timer_check, TIMER_FLAG_DELAY_ON_DELAY) < 0) {
		LM_ERR("failed to register profiles utimer\n");
		return -1;
	}

	if (!profile_replicate_cluster)
		return 0;

	if (repl_prof_utimer < 0) {
		LM_ERR("negative replicate timer for profiles %d\n", repl_prof_utimer);
		return -1;
	}

	if (repl_prof_buffer_th < 0) {
		LM_ERR("negative replicate buffer threshold for profiles %d\n",
			repl_prof_buffer_th);
		return -1;
	}

	if (register_utimer("dialog-repl-profiles-utimer", repl_prof_utimer_f, NULL,
		repl_prof_utimer * 1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) {
		LM_ERR("failed to register profiles utimer\n");
		return -1;
	}


	if (repl_prof_buffer_th > (BUF_SIZE * 0.9)) {
		LM_WARN("Buffer size too big %d - profiles information might get lost",
			repl_prof_buffer_th);
		return -1;
	}

	return 0;
}
Exemple #17
0
/*! \brief
 * Module initialization function
 */
static int mod_init(void) {

	if (usrloc_debug){
		LM_INFO("Logging usrloc records to %.*s\n", usrloc_debug_file.len, usrloc_debug_file.s);
		debug_file = fopen(usrloc_debug_file.s, "a");
		fprintf(debug_file, "starting\n");
		fflush(debug_file);
	}

#ifdef STATISTICS
	/* register statistics */
	if (register_module_stats( exports.name, mod_stats)!=0 ) {
		LM_ERR("failed to register core statistics\n");
		return -1;
	}
#endif

	/* Compute the lengths of string parameters */
	usrloc_debug_file.len = strlen(usrloc_debug_file.s);

	if (ul_hash_size <= 1)
		ul_hash_size = 512;
	else
		ul_hash_size = 1 << ul_hash_size;
	ul_locks_no = ul_hash_size;

	if (ul_init_locks() != 0) {
		LM_ERR("locks array initialization failed\n");
		return -1;
	}

	/* Regsiter RPC */
	if (rpc_register_array(ul_rpc) != 0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	/* Register cache timer */
	LM_DBG("Registering cache timer");
	register_timer(timer, 0, timer_interval);

	/* init the callbacks list */
	if (init_ulcb_list() < 0) {
		LM_ERR("usrloc/callbacks initialization failed\n");
		return -1;
	}

	init_flag = 1;

	return 0;
}
Exemple #18
0
/* initialize ratelimit module */
static int mod_init(void)
{
	DBG("RATELIMIT: initializing ...\n");

	/* register timer to reset counters */
	if (register_timer(timer, 0, timer_interval) < 0) {
		LOG(L_ERR, "RATELIMIT:ERROR: could not register timer function\n");
		return -1;
	}

	invite_counter = shm_malloc(sizeof(int));
	register_counter = shm_malloc(sizeof(int));
	subscribe_counter = shm_malloc(sizeof(int));
	if (!invite_counter || !register_counter || !subscribe_counter) {
		LOG(L_ERR, "RATELIMIT:ERROR: no memory for counters\n");
		return -1;
	}
	*invite_counter = 0;
	*register_counter = 0;
	*subscribe_counter = 0;

	invite_limit = shm_malloc(sizeof(int));
	register_limit = shm_malloc(sizeof(int));
	subscribe_limit = shm_malloc(sizeof(int));
	if (!invite_limit || !register_limit || !subscribe_limit) {
		LOG(L_ERR, "RATELIMIT:ERROR: no memory for limit settings\n");
		return -1;
	}
	/* obtain limits from modparam */
	*invite_limit = invite_limit_mp;
	*register_limit = register_limit_mp;
	*subscribe_limit = subscribe_limit_mp;


#if defined (RL_WITH_RED)
	/* these are only needed when using RED */
	invite_load = shm_malloc(sizeof(int));
	register_load = shm_malloc(sizeof(int));
	subscribe_load = shm_malloc(sizeof(int));
	if (!invite_load || !register_load || !subscribe_load) {
		LOG(L_ERR, "RATELIMIT:ERROR: no memory for load levels\n");
		return -1;
	}
	*invite_load = -1; /* -1 = first run identifier */
	*register_load = -1;
	*subscribe_load = -1;
#endif

	return 0;
}
Exemple #19
0
/*! This is the first function to be called by Kamailio, to initialize the module.
 * This call must always return a value as soon as possible.  If it were not to
 * return, then Kamailio would not be able to initialize any of the other
 * modules. */
static int mod_init(void) 
{
	if (register_message_code_statistics() < 0) 
	{
		return -1;
	}

	/* Initialize shared memory used to buffer communication between the
	 * usrloc module and the snmpstats module.  */
	initInterprocessBuffers();
	
	/* We need to register for callbacks with usrloc module, for whenever a
	 * contact is added or removed from the system.  We need to do it now
	 * before Kamailio's functions get a chance to load up old user data from
	 * the database.  That load will happen if a lookup() function is come
	 * across in kamailio.cfg. */

	if (snmp_export_registrar!=0)
	{
		if(!registerForUSRLOCCallbacks())
		{
			/* Originally there were descriptive error messages here to help
			 * the operator debug problems.  Turns out this may instead
			 * alarm them about problems they don't need to worry about.  So
			 * the messages are commented out for now */
		
			/*
			LM_ERR("snmpstats module was unable to register callbacks"
					" with the usrloc module\n");
			LM_ERR("Are you sure that the usrloc module was loaded"
					" before the snmpstats module in ");
			LM_ERR("kamailio.cfg?  kamailioSIPRegUserTable will not be "
				   "updated.");
			*/
		}
	}

	/* Register the alarm checking function to run periodically */
	register_timer(run_alarm_check, 0, ALARM_AGENT_FREQUENCY_IN_SECONDS);

	/* add space for one extra process */
	register_procs(1);
	/* add child to update local config framework structures */
	cfg_register_child(1);
	/* Initialize config framework in utilities.c */
	config_context_init();

	return 0;
}
static int
mod_init(void)
{

	if (natping_interval > 0) {
		get_all_ucontacts =
		    (int (*)(void *, int))find_export("ul_get_all_ucontacts", 1, 0);
		if (!get_all_ucontacts) {
			LOG(L_ERR, "This module requires usrloc module\n");
			return -1;
		}
		register_timer(timer, NULL, natping_interval);
	}

	return 0;
}
Exemple #21
0
/* Initializes needed structures and registeres timer
 *
 * Important : To be called before forking so all processes
 * inherit same queue */
int init_ql_support(void)
{
	if (query_buffer_size > 1)
	{
		if  (init_query_list() != 0 ||
			register_timer("querydb-flush", ql_timer_routine,NULL,
				query_flush_time>0?query_flush_time:DEF_FLUSH_TIME,
				TIMER_FLAG_DELAY_ON_DELAY) < 0 )
		{
			LM_ERR("failed initializing ins list support\n");
			return -1;
		}
	}

	return 0;
}
Exemple #22
0
/**
 * init module function
 */
static int mod_init(void)
{
	str _s;
	int ver;

	xcap_db_url.len = xcap_db_url.s ? strlen(xcap_db_url.s) : 0;
	
	/* binding to mysql module  */
	if (bind_dbmod(xcap_db_url.s, &xcap_dbf))
	{
		LM_ERR("Database module not found\n");
		return -1;
	}
	
	if (!DB_CAPABILITY(xcap_dbf, DB_CAP_ALL)) {
		LM_ERR("Database module does not implement all functions"
				" needed by the module\n");
		return -1;
	}

	xcap_db = xcap_dbf.init(xcap_db_url.s);
	if (!xcap_db)
	{
		LM_ERR("while connecting to database\n");
		return -1;
	}

	_s.s = xcap_db_table;
	_s.len = strlen(xcap_db_table);
	 ver =  table_version(&xcap_dbf, xcap_db, &_s);
	if(ver!=XCAP_TABLE_VERSION)
	{
		LM_ERR("Wrong version v%d for table <%s>, need v%d\n",
				 ver, _s.s, XCAP_TABLE_VERSION);
		return -1;
	}

	curl_global_init(CURL_GLOBAL_ALL);

	if(periodical_query)
	{
		register_timer(query_xcap_update, 0, query_period);
	}
	return 0;
}
Exemple #23
0
static int l_set_timer(lua_State *L)
{
    unsigned long expire;
    int timeout;
    struct timer_list* timer;

    timer = lua_checktimer(L, 1);
    timeout = luaL_checkinteger(L, 2);
    luaL_argcheck(L, timeout >= 0, 2, "negative timeout");

    expire = (unsigned long)times(0) + ((unsigned long)timeout + (MS_PER_TICK-1)) / MS_PER_TICK;

    set_timer(timer, expire, callback, L);
    add_timer(&timers, timer);
    register_timer(L, 1, timer);

    return 0;
}
Exemple #24
0
/**
 * init module function
 */
static int mod_init(void)
{
	if(xcap_client_init_rpc()<0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	/* binding to mysql module  */
	if (db_bind_mod(&xcap_db_url, &xcap_dbf))
	{
		LM_ERR("Database module not found\n");
		return -1;
	}

	if (!DB_CAPABILITY(xcap_dbf, DB_CAP_ALL)) {
		LM_ERR("Database module does not implement all functions"
				" needed by the module\n");
		return -1;
	}

	xcap_db = xcap_dbf.init(&xcap_db_url);
	if (!xcap_db)
	{
		LM_ERR("while connecting to database\n");
		return -1;
	}

	if(db_check_table_version(&xcap_dbf, xcap_db, &xcap_db_table,
				XCAP_TABLE_VERSION) < 0) {
		LM_ERR("error during table version check.\n");
		return -1;
	}
	xcap_dbf.close(xcap_db);
	xcap_db = NULL;

	curl_global_init(CURL_GLOBAL_ALL);

	if(periodical_query)
	{
		register_timer(query_xcap_update, 0, query_period);
	}
	return 0;
}
Exemple #25
0
/*
#<pydoc>
def register_timer(interval, callback):
    """
    Register a timer

    @param interval: Interval in milliseconds
    @param callback: A Python callable that takes no parameters and returns an integer.
                     The callback may return:
                     -1   : to unregister the timer
                     >= 0 : the new or same timer interval
    @return: None or a timer object
    """
    pass
#</pydoc>
*/
static PyObject *py_register_timer(int interval, PyObject *py_callback)
{
  PYW_GIL_CHECK_LOCKED_SCOPE();

  if ( py_callback == NULL || !PyCallable_Check(py_callback) )
    Py_RETURN_NONE;

  // An inner class hosting the callback method
  struct tmr_t
  {
    static int idaapi callback(void *ud)
    {
      PYW_GIL_GET;
      py_timer_ctx_t *ctx = (py_timer_ctx_t *)ud;
      newref_t py_result(PyObject_CallFunctionObjArgs(ctx->pycallback, NULL));
      int ret = py_result == NULL ? -1 : PyLong_AsLong(py_result.o);

      // Timer has been unregistered?
      if ( ret == -1 )
      {
        // Free the context
        Py_DECREF(ctx->pycallback);
        delete ctx;
      }
      return ret;
    };
  };

  py_timer_ctx_t *ctx = new py_timer_ctx_t();
  ctx->pycallback = py_callback;
  Py_INCREF(py_callback);
  ctx->timer_id = register_timer(
    interval,
    tmr_t::callback,
    ctx);

  if ( ctx->timer_id == NULL )
  {
    Py_DECREF(py_callback);
    delete ctx;
    Py_RETURN_NONE;
  }
  return PyCObject_FromVoidPtr(ctx, NULL);
}
Exemple #26
0
int time_event_management_init()
{
	if (tem_info) return 0; /* already initialized */
	
	tem_info = (tem_info_t *)mem_alloc(sizeof(tem_info_t));
	if (!tem_info) {
		LOG(L_ERR, "time_event_management_init(): can't allocate shared memory\n");
		return -1;
	}
	tem_info->first = NULL;
	tem_info->last = NULL;
	lock_init(&tem_info->structure_mutex);
	
	/* register a SER timer */
	if (register_timer(tem_timer_cb, NULL, 1) < 0) {
		LOG(L_ERR, "time_event_management_init(): can't register timer\n");
		return -1;
	}
	return 0;
}
Exemple #27
0
int init_black_lists(void)
{
	bl_ctx_idx = context_register_int(CONTEXT_GLOBAL, NULL);
	if (bl_ctx_idx < 0)
		return -1;

	/* register timer routine  */
	if (register_timer("blcore-expire", delete_expired_routine, 0, 1,
	    TIMER_FLAG_SKIP_ON_DELAY) < 0) {
		LM_ERR("failed to register timer\n");
		return -1;
	}

	/* register MI commands */
	if (register_mi_mod("blacklists", mi_bl_cmds) < 0) {
		LM_ERR("unable to register MI cmds\n");
		return -1;
	}

	return 0;
}
Exemple #28
0
void bx_virt_timer_c::init(void)
{
  if ((SIM->get_param_enum(BXPN_CLOCK_SYNC)->get()!=BX_CLOCK_SYNC_REALTIME) &&
      (SIM->get_param_enum(BXPN_CLOCK_SYNC)->get()!=BX_CLOCK_SYNC_BOTH))
    virtual_timers_realtime = 0;
  else
    virtual_timers_realtime = 1;

  if (virtual_timers_realtime) {
    BX_INFO(("using 'realtime pit' synchronization method"));
  }

  // Local copy of IPS value to avoid reading it frequently in timer handler
  ips = SIM->get_param_num(BXPN_IPS)->get();

  register_timer(this, nullTimer, (Bit32u)NullTimerInterval, 1, 1, "Null Timer");

  system_timer_id = bx_pc_system.register_timer(this, pc_system_timer_handler,
                                                (Bit32u)virtual_next_event_time, 0, 1, "Virtual Timer");

  //Real time variables:
#if BX_HAVE_REALTIME_USEC
  last_real_time = GET_VIRT_REALTIME64_USEC();
#endif
  total_real_usec = 0;
  last_realtime_delta = 0;
  real_time_delay = 0;
  //System time variables:
  last_usec = 0;
  usec_per_second = USEC_PER_SECOND;
  stored_delta = 0;
  last_system_usec = 0;
  em_last_realtime = 0;
  //Virtual timer variables:
  total_ticks = 0;
  last_realtime_ticks = 0;
  ticks_per_second = USEC_PER_SECOND;

  init_done = 1;
}
int init_dlg_db(const str *db_url, int dlg_hash_size , int db_update_period)
{
	/* Find a database module */
	if (db_bind_mod(db_url, &dialog_dbf) < 0){
		LM_ERR("Unable to bind to a database driver\n");
		return -1;
	}

	if (dlg_connect_db(db_url)!=0){
		LM_ERR("unable to connect to the database\n");
		return -1;
	}

	if(db_check_table_version(&dialog_dbf, dialog_db_handle,
	&dialog_table_name, DLG_TABLE_VERSION) < 0) {
		LM_ERR("error during table version check.\n");
		return -1;
	}

	if( (dlg_db_mode==DB_MODE_DELAYED) &&
	(register_timer( dialog_update_db, 0, db_update_period)<0 )) {
		LM_ERR("failed to register update db\n");
		return -1;
	}

	if( (load_dialog_info_from_db(dlg_hash_size) ) !=0 ){
		LM_ERR("unable to load the dialog data\n");
		return -1;
	}

	if (dlg_db_mode==DB_MODE_SHUTDOWN && remove_all_dialogs_from_db()!=0) {
		LM_WARN("failed to properly remove all the dialogs form DB\n");
	}

	dialog_dbf.close(dialog_db_handle);
	dialog_db_handle = 0;

	return 0;
}
Exemple #30
0
static int init_monitor(void)
{
	unsigned int i;
	TIME_STEP = sampling_rate * HZ / 1000;
	printk("[Monitor] Monitor init\n");

	pgdata = kmalloc(sizeof(struct cpu_monitor_info_s), GFP_KERNEL);
	if(pgdata == NULL)	return -ENOMEM;
	memset(pgdata, 0x00, sizeof(struct cpu_monitor_info_s));

	/* Initialize cpu_monitor_info_s pgdata */

	for(i=0; i<NUM_CPUS; ++i)
	{
		pgdata->cpu_info[i].cpuid = i;
		pgdata->cpu_info[i].prev_cpu_idle = get_cpu_idle_time_us(i, &(pgdata->cpu_info[0].prev_cpu_wall));
	}

	register_timer(pgdata, TIME_STEP);

	return 0;
}