Exemplo n.º 1
0
static void run_hashtest(int numthr)
{
	pthread_t thr[numthr];
	void *thrres[numthr];
	int i;
	
	/* init a single global hashtab, then... */
	glob_hashtab = ao2_container_alloc(180000, hash_string, hashtab_compare_strings);

	/* set a random seed  */
	glob_seed = (unsigned int)time(0);
	srand(glob_seed);
	
	/* create threads, each running hashtest */
	for(i=0;i<numthr;i++)
	{
		unsigned long z = rand();
		
		printf("starting hashtest thread %d....\n",i+1);
		if (ast_pthread_create(&thr[i], NULL, hashtest, (void*)z)) {
			printf("Sorry, couldn't create thread #%d\n", i+1);
		}
		printf("hashtest thread spawned.... \n");
	}
	/* collect threads, each running hashtest */
	for(i=0;i<numthr;i++)
	{
		printf("waiting for thread %d....\n", i+1);
		if (pthread_join(thr[i], &thrres[i])) {
			printf("Sorry, couldn't join thread #%d\n", i+1);
		}
		printf("hashtest thread %d done.... \n",i+1);
	}
	/* user has to kill/intr the process to stop the test? */
}
Exemplo n.º 2
0
int ast_autoservice_start(struct ast_channel *chan)
{
	int res = -1;
	struct asent *as;
	int needstart;
	ast_mutex_lock(&autolock);
	needstart = (asthread == AST_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
	as = aslist;
	while(as) {
		if (as->chan == chan)
			break;
		as = as->next;
	}
	if (!as) {
		as = malloc(sizeof(struct asent));
		if (as) {
			memset(as, 0, sizeof(struct asent));
			as->chan = chan;
			as->next = aslist;
			aslist = as;
			res = 0;
			if (needstart) {
				if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
					ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
					free(aslist);
					aslist = NULL;
					res = -1;
				} else
					pthread_kill(asthread, SIGURG);
			}
		}
	}
	ast_mutex_unlock(&autolock);
	return res;
}
Exemplo n.º 3
0
static int restart_monitor()
{
	/* If we're supposed to be stopped -- stay stopped */
	if (monitor_thread == AST_PTHREADT_STOP)
		return 0;
	if (ast_mutex_lock(&monlock)) {
		ast_log(LOG_WARNING, "Unable to lock monitor\n");
		return -1;
	}
	if (monitor_thread == pthread_self()) {
		ast_mutex_unlock(&monlock);
		ast_log(LOG_WARNING, "Cannot kill myself\n");
		return -1;
	}
	if (monitor_thread != AST_PTHREADT_NULL) {
		pthread_cancel(monitor_thread);
#if 0
		pthread_join(monitor_thread, NULL);
#endif
	}
	/* Start a new monitor */
	if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
		ast_mutex_unlock(&monlock);
		ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
		return -1;
	}
	ast_mutex_unlock(&monlock);
	return 0;
}
Exemplo n.º 4
0
static void http_server_start(struct sockaddr_in *sin)
{
	char iabuf[INET_ADDRSTRLEN];
	int flags;
	int x = 1;
	
	/* Do nothing if nothing has changed */
	if (!memcmp(&oldsin, sin, sizeof(oldsin))) {
		ast_log(LOG_DEBUG, "Nothing changed in http\n");
		return;
	}
	
	memcpy(&oldsin, sin, sizeof(oldsin));
	
	/* Shutdown a running server if there is one */
	if (master != AST_PTHREADT_NULL) {
		pthread_cancel(master);
		pthread_kill(master, SIGURG);
		pthread_join(master, NULL);
	}
	
	if (httpfd != -1)
		close(httpfd);

	/* If there's no new server, stop here */
	if (!sin->sin_family)
		return;
	
	
	httpfd = socket(AF_INET, SOCK_STREAM, 0);
	if (httpfd < 0) {
		ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
		return;
	}
	
	setsockopt(httpfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
	if (bind(httpfd, (struct sockaddr *)sin, sizeof(*sin))) {
		ast_log(LOG_NOTICE, "Unable to bind http server to %s:%d: %s\n",
			ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port),
			strerror(errno));
		close(httpfd);
		httpfd = -1;
		return;
	}
	if (listen(httpfd, 10)) {
		ast_log(LOG_NOTICE, "Unable to listen!\n");
		close(httpfd);
		httpfd = -1;
		return;
	}
	flags = fcntl(httpfd, F_GETFL);
	fcntl(httpfd, F_SETFL, flags | O_NONBLOCK);
	if (ast_pthread_create(&master, NULL, http_root, NULL)) {
		ast_log(LOG_NOTICE, "Unable to launch http server on %s:%d: %s\n",
				ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port),
				strerror(errno));
		close(httpfd);
		httpfd = -1;
	}
}
Exemplo n.º 5
0
static void *snooze_alarm(void *pass)
{
	pthread_t dialstring_thread;
	struct alarm_data *data = (struct alarm_data *) pass;

	sleep(data->snooze_len);
	ast_pthread_create(&dialstring_thread, NULL, dialstring, data->dialstr);
	/* dialstring will free data->dialstr */
	free(pass);
	pthread_exit(NULL);
	return NULL;
}
Exemplo n.º 6
0
static void launch_service(struct outgoing *o)
{
	pthread_t t;
	pthread_attr_t attr;
	int ret;
	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	if ((ret = ast_pthread_create(&t,&attr,attempt_thread, o)) != 0) {
		ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
		free_outgoing(o);
	}
	pthread_attr_destroy(&attr);
}
Exemplo n.º 7
0
int load_module(void)
{
	int val;

	snprintf((char *)dialfile, sizeof(dialfile), "%s/%s", ast_config_AST_RUN_DIR, "autodial.ctl");
	if((val=mkfifo(dialfile, 0700))) {
		if(errno!=EEXIST){
			ast_log(LOG_ERROR, "Error:%d Creating Autodial FIFO\n",errno);
			return 0;
		}
	}
	ast_pthread_create(&autodialer_thread, NULL, autodial, NULL);
	return 0;
}
Exemplo n.º 8
0
/*! \brief Helper function which adds or removes a channel and nudges the thread */
static void multiplexed_add_or_remove(struct multiplexed_thread *multiplexed_thread, struct ast_channel *chan, int add)
{
	int i, removed = 0;
	pthread_t thread = AST_PTHREADT_NULL;

	ao2_lock(multiplexed_thread);

	multiplexed_nudge(multiplexed_thread);

	for (i = 0; i < MULTIPLEXED_MAX_CHANNELS; i++) {
		if (multiplexed_thread->chans[i] == chan) {
			if (!add) {
				multiplexed_thread->chans[i] = NULL;
				multiplexed_thread->service_count--;
				removed = 1;
			}
			break;
		} else if (!multiplexed_thread->chans[i] && add) {
			multiplexed_thread->chans[i] = chan;
			multiplexed_thread->service_count++;
			break;
		}
	}

	if (multiplexed_thread->service_count && multiplexed_thread->thread == AST_PTHREADT_NULL) {
		ao2_ref(multiplexed_thread, +1);
		if (ast_pthread_create(&multiplexed_thread->thread, NULL, multiplexed_thread_function, multiplexed_thread)) {
			ao2_ref(multiplexed_thread, -1);
			ast_debug(1, "Failed to create an actual thread for multiplexed thread '%p', trying next time\n", multiplexed_thread);
		}
	} else if (!multiplexed_thread->service_count && multiplexed_thread->thread != AST_PTHREADT_NULL) {
		thread = multiplexed_thread->thread;
		multiplexed_thread->thread = AST_PTHREADT_STOP;
	} else if (!add && removed) {
		memmove(multiplexed_thread->chans + i, multiplexed_thread->chans + i + 1, sizeof(struct ast_channel *) * (MULTIPLEXED_MAX_CHANNELS - (i + 1)));
	}

	ao2_unlock(multiplexed_thread);

	if (thread != AST_PTHREADT_NULL) {
		pthread_join(thread, NULL);
	}

	return;
}
Exemplo n.º 9
0
static void  set_snooze_alarm(char *dialstr, int snooze_len)
{
	pthread_t snooze_alarm_thread;
	struct alarm_data *pass;

	ast_log(LOG_DEBUG, "Answered: Snooze Requested\n");
	if (NULL==(pass=malloc(sizeof(struct alarm_data)))){
		perror("snooze_alarm: data");
		pthread_exit(NULL);
	}
	if (NULL==(pass->dialstr=(void *)strdup(dialstr))){
		free(pass);
		perror("snooze_alarm: dialstr");
		pthread_exit(NULL);
	}
	pass->snooze_len=snooze_len;
	ast_pthread_create(&snooze_alarm_thread,NULL,snooze_alarm,pass);
}
Exemplo n.º 10
0
static int ss7_load_module(void)
{
  if(load_config(0)) {
    return AST_MODULE_LOAD_FAILURE;
  }

  if (timers_init()) {
    ast_log(LOG_ERROR, "Unable to initialize timers.\n");
    return AST_MODULE_LOAD_FAILURE;
  }
  if (isup_init()) {
    ast_log(LOG_ERROR, "Unable to initialize ISUP.\n");
    return AST_MODULE_LOAD_FAILURE;
  }
#ifdef SCCP
  if (sccp_init()) {
    ast_log(LOG_ERROR, "Unable to initialize SCCP.\n");
    return AST_MODULE_LOAD_FAILURE;
  }
#endif

  if(mtp_init()) {
    ast_log(LOG_ERROR, "Unable to initialize MTP.\n");
    return AST_MODULE_LOAD_FAILURE;
  }
  if(start_mtp_thread()) {
    ast_log(LOG_ERROR, "Unable to start MTP thread.\n");
    return AST_MODULE_LOAD_FAILURE;
  }
  monitor_running = 1;          /* Otherwise there is a race, and
                                   monitor may exit immediately */
  if(ast_pthread_create(&monitor_thread, NULL, monitor_main, NULL) < 0) {
    ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
    monitor_running = 0;
    return AST_MODULE_LOAD_FAILURE;
  }


  cli_register();

  ast_verbose(VERBOSE_PREFIX_3 "SS7 channel loaded successfully.\n");
  return AST_MODULE_LOAD_SUCCESS;
}
Exemplo n.º 11
0
static void *http_root(void *data)
{
	int fd;
	struct sockaddr_in sin;
	int sinlen;
	struct ast_http_server_instance *ser;
	pthread_t launched;
	pthread_attr_t attr;
	
	for (;;) {
		ast_wait_for_input(httpfd, -1);
		sinlen = sizeof(sin);
		fd = accept(httpfd, (struct sockaddr *)&sin, &sinlen);
		if (fd < 0) {
			if ((errno != EAGAIN) && (errno != EINTR))
				ast_log(LOG_WARNING, "Accept failed: %s\n", strerror(errno));
			continue;
		}
		ser = ast_calloc(1, sizeof(*ser));
		if (ser) {
			ser->fd = fd;
			memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
			if ((ser->f = fdopen(ser->fd, "w+"))) {
				pthread_attr_init(&attr);
				pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
				
				if (ast_pthread_create(&launched, &attr, ast_httpd_helper_thread, ser)) {
					ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
					fclose(ser->f);
					free(ser);
				}
			} else {
				ast_log(LOG_WARNING, "fdopen failed!\n");
				close(ser->fd);
				free(ser);
			}
		}
	}
	return NULL;
}
Exemplo n.º 12
0
static void run_hashtest(int numthr)
{
	pthread_t thr[numthr];
	void *thrres[numthr];
	int i, biggest, resize_cnt, numobjs, numbuckets;
	
	/* init a single global hashtab, then... */
	glob_hashtab = ast_hashtab_create(180000, hashtab_compare_strings_nocase, ast_hashtab_resize_java, ast_hashtab_newsize_java, hashtab_hash_string_nocase, 1);
	printf("starting with %d elements in the hashtable...\n", ast_hashtab_capacity(glob_hashtab));
	/* set a random seed  */
	glob_seed = (unsigned int)time(0);
	srand(glob_seed);
	
	/* create threads, each running hashtest */
	for(i=0;i<numthr;i++)
	{
		unsigned long z = rand();
		
		printf("starting hashtest thread %d....\n",i+1);
		if (ast_pthread_create(&thr[i], NULL, hashtest, (void*)z)) {
			printf("Sorry, couldn't create thread #%d\n", i+1);
		}
		printf("hashtest thread spawned.... \n");
	}
	/* collect threads, each running hashtest */
	for(i=0;i<numthr;i++)
	{
		printf("waiting for thread %d....\n", i+1);
		if (pthread_join(thr[i], &thrres[i])) {
			printf("Sorry, couldn't join thread #%d\n", i+1);
		}
		printf("hashtest thread %d done.... \n",i+1);
	}
	/* user has to kill/intr the process to stop the test? */
	ast_hashtab_get_stats(glob_hashtab, &biggest, &resize_cnt, &numobjs, &numbuckets);
	printf("Some stats: longest bucket chain: %d;  number of resizes: %d; number of objects: %d;  capacity: %d\n",
			biggest, resize_cnt, numobjs, numbuckets);
}
Exemplo n.º 13
0
static void *autodial(void *ignore)
{
	pthread_t dialstring_thread;
	char * sendbufptr=sendbuf;
	int fd=open(dialfile,O_RDONLY|O_NONBLOCK);
	int flags = fcntl(fd, F_GETFL);
	struct pollfd fds[1];

	fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
	if (option_debug)
		ast_log(LOG_DEBUG, "Entered Wil-Calu fd=%d\n",fd);
	if(fd<0) {
		ast_log(LOG_WARNING, "Autodial: Unable to open file\n");
		pthread_exit(NULL);
	}
	memset(buf,0,257);
	memset(lastbuf,0,257);
	memset(sendbuf,0,257);
	while(1){
		ssize_t bytes;
		void *pass;

		memset(buf,0,257);
		fds[0].fd = fd;
		fds[0].events = POLLIN;
		poll(fds, 1, -1);
		bytes=read(fd,buf,256);
		buf[(int)bytes]=0;

		if(bytes>0){
			int x;
			ast_log(LOG_DEBUG, "WilCalu : Read Buf %s\n",buf);
			sendbufptr=sendbuf;
			for(x=0; lastbuf[x]!=0 && x<257; x++);
			if(x) {
				memcpy(sendbuf, lastbuf, x);
				sendbufptr+=x;
				memset(lastbuf, 0, 257);
			}
			/* Process bytes read */
			for(x=0; x<bytes; x++){
				/* if & then string is complete */
				if(buf[x]=='&'){
					if(NULL!=(pass=(void *)strdup(sendbuf))){
						ast_pthread_create(&dialstring_thread, NULL, dialstring, pass);
						sendbufptr=sendbuf;
						memset(sendbuf, 0, 257);
					}
					else {
						perror("Autodial: Strdup failed");
						close(fd);
						pthread_exit(NULL);
					}
				} else {
					if(buf[x]=='\n')
						continue;
					*sendbufptr=buf[x];
					sendbufptr++;
					*sendbufptr=0;
				}
			}
			if(sendbufptr!=sendbuf)
				memcpy(lastbuf, sendbuf, sendbufptr-sendbuf+1);
		}
	}
	close(fd);
	pthread_exit(NULL);
	return NULL;
}
Exemplo n.º 14
0
/*!
 * \internal
 * \brief Load and reload SMDI configuration.
 * \param reload this should be 1 if we are reloading and 0 if not.
 *
 * This function loads/reloads the SMDI configuration and starts and stops
 * interfaces accordingly.
 *
 * \return zero on success, -1 on failure, and 1 if no smdi interfaces were started.
 */
static int smdi_load(int reload)
{
	struct ast_config *conf;
	struct ast_variable *v;
	struct ast_smdi_interface *iface = NULL;
	int res = 0;

	/* Config options */
	speed_t baud_rate = B9600;     /* 9600 baud rate */
	tcflag_t paritybit = PARENB;   /* even parity checking */
	tcflag_t charsize = CS7;       /* seven bit characters */
	int stopbits = 0;              /* One stop bit */
	
	int msdstrip = 0;              /* strip zero digits */
	long msg_expiry = SMDI_MSG_EXPIRY_TIME;
	
	conf = ast_config_load(config_file);

	if (!conf) {
		if (reload)
			ast_log(LOG_NOTICE, "Unable to reload config %s: SMDI untouched\n", config_file);
		else
			ast_log(LOG_NOTICE, "Unable to load config %s: SMDI disabled\n", config_file);
		return 1;
	}

	/* Mark all interfaces that we are listening on.  We will unmark them
	 * as we find them in the config file, this way we know any interfaces
	 * still marked after we have finished parsing the config file should
	 * be stopped.
	 */
	if (reload)
		ASTOBJ_CONTAINER_MARKALL(&smdi_ifaces);

	for (v = ast_variable_browse(conf, "interfaces"); v; v = v->next) {
		if (!strcasecmp(v->name, "baudrate")) {
			if (!strcasecmp(v->value, "9600"))
				baud_rate = B9600;
			else if(!strcasecmp(v->value, "4800"))
				baud_rate = B4800;
			else if(!strcasecmp(v->value, "2400"))
				baud_rate = B2400;
			else if(!strcasecmp(v->value, "1200"))
				baud_rate = B1200;
			else {
				ast_log(LOG_NOTICE, "Invalid baud rate '%s' specified in %s (line %d), using default\n", v->value, config_file, v->lineno);
				baud_rate = B9600;
			}
		} else if (!strcasecmp(v->name, "msdstrip")) {
			if (!sscanf(v->value, "%d", &msdstrip)) {
				ast_log(LOG_NOTICE, "Invalid msdstrip value in %s (line %d), using default\n", config_file, v->lineno);
				msdstrip = 0;
			} else if (0 > msdstrip || msdstrip > 9) {
				ast_log(LOG_NOTICE, "Invalid msdstrip value in %s (line %d), using default\n", config_file, v->lineno);
				msdstrip = 0;
			}
		} else if (!strcasecmp(v->name, "msgexpirytime")) {
			if (!sscanf(v->value, "%ld", &msg_expiry)) {
				ast_log(LOG_NOTICE, "Invalid msgexpirytime value in %s (line %d), using default\n", config_file, v->lineno);
				msg_expiry = SMDI_MSG_EXPIRY_TIME;
			}
		} else if (!strcasecmp(v->name, "paritybit")) {
			if (!strcasecmp(v->value, "even"))
				paritybit = PARENB;
			else if (!strcasecmp(v->value, "odd"))
				paritybit = PARENB | PARODD;
			else if (!strcasecmp(v->value, "none"))
				paritybit = ~PARENB;
			else {
				ast_log(LOG_NOTICE, "Invalid parity bit setting in %s (line %d), using default\n", config_file, v->lineno);
				paritybit = PARENB;
			}
		} else if (!strcasecmp(v->name, "charsize")) {
			if (!strcasecmp(v->value, "7"))
				charsize = CS7;
			else if (!strcasecmp(v->value, "8"))
				charsize = CS8;
			else {
				ast_log(LOG_NOTICE, "Invalid character size setting in %s (line %d), using default\n", config_file, v->lineno);
				charsize = CS7;
			}
		} else if (!strcasecmp(v->name, "twostopbits")) {
			stopbits = ast_true(v->name);
		} else if (!strcasecmp(v->name, "smdiport")) {
			if (reload) {
				/* we are reloading, check if we are already
				 * monitoring this interface, if we are we do
				 * not want to start it again.  This also has
				 * the side effect of not updating different
				 * setting for the serial port, but it should
				 * be trivial to rewrite this section so that
				 * options on the port are changed without
				 * restarting the interface.  Or the interface
				 * could be restarted with out emptying the
				 * queue. */
				if ((iface = ASTOBJ_CONTAINER_FIND(&smdi_ifaces, v->value))) {
					ast_log(LOG_NOTICE, "SMDI interface %s already running, not restarting\n", iface->name);
					ASTOBJ_UNMARK(iface);
					ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
					continue;
				}
			}
							
			if (!(iface = ast_calloc(1, sizeof(*iface))))
				continue;

			ASTOBJ_INIT(iface);
			ASTOBJ_CONTAINER_INIT(&iface->md_q);
			ASTOBJ_CONTAINER_INIT(&iface->mwi_q);

			ast_copy_string(iface->name, v->value, sizeof(iface->name));

			if (!(iface->file = fopen(iface->name, "r"))) {
				ast_log(LOG_ERROR, "Error opening SMDI interface %s (%s)\n", iface->name, strerror(errno));
				ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
				continue;
			}

			iface->fd = fileno(iface->file);

			/* Set the proper attributes for our serial port. */

			/* get the current attributes from the port */
			if (tcgetattr(iface->fd, &iface->mode)) {
				ast_log(LOG_ERROR, "Error getting atributes of %s (%s)\n", iface->name, strerror(errno));
				ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
				continue;
			}

			/* set the desired speed */
			if (cfsetispeed(&iface->mode, baud_rate) || cfsetospeed(&iface->mode, baud_rate)) {
				ast_log(LOG_ERROR, "Error setting baud rate on %s (%s)\n", iface->name, strerror(errno));
				ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
				continue;
			}
			
			/* set the stop bits */
			if (stopbits)
			   iface->mode.c_cflag = iface->mode.c_cflag | CSTOPB;   /* set two stop bits */
			else
			   iface->mode.c_cflag = iface->mode.c_cflag & ~CSTOPB;  /* set one stop bit */

			/* set the parity */
			iface->mode.c_cflag = (iface->mode.c_cflag & ~PARENB & ~PARODD) | paritybit;

			/* set the character size */
			iface->mode.c_cflag = (iface->mode.c_cflag & ~CSIZE) | charsize;
			
			/* commit the desired attributes */
			if (tcsetattr(iface->fd, TCSAFLUSH, &iface->mode)) {
				ast_log(LOG_ERROR, "Error setting attributes on %s (%s)\n", iface->name, strerror(errno));
				ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
				continue;
			}

			/* set the msdstrip */
			iface->msdstrip = msdstrip;

			/* set the message expiry time */
			iface->msg_expiry = msg_expiry;

                        /* start the listner thread */
			if (option_verbose > 2)
				ast_verbose(VERBOSE_PREFIX_3 "Starting SMDI monitor thread for %s\n", iface->name);
			if (ast_pthread_create(&iface->thread, NULL, smdi_read, iface)) {
				ast_log(LOG_ERROR, "Error starting SMDI monitor thread for %s\n", iface->name);
				ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
				continue;
			}

			ASTOBJ_CONTAINER_LINK(&smdi_ifaces, iface);
			ASTOBJ_UNREF(iface, ast_smdi_interface_destroy);
			ast_atomic_fetchadd_int(&me->usecnt, +1);
		} else {
			ast_log(LOG_NOTICE, "Ignoring unknown option %s in %s\n", v->name, config_file);
		}
	}
	ast_config_destroy(conf);

	/* Prune any interfaces we should no longer monitor. */
	if (reload)
		ASTOBJ_CONTAINER_PRUNE_MARKED(&smdi_ifaces, ast_smdi_interface_destroy);
	
	ASTOBJ_CONTAINER_RDLOCK(&smdi_ifaces);
	/* TODO: this is bad, we need an ASTOBJ method for this! */
	if (!smdi_ifaces.head)
		res = 1;
	ASTOBJ_CONTAINER_UNLOCK(&smdi_ifaces);
			
	return res;
}
Exemplo n.º 15
0
static int worker_thread_start(struct worker_thread *worker)
{
	return ast_pthread_create(&worker->thread, NULL, worker_start, worker);
}
Exemplo n.º 16
0
static int show_console(void)
{
	GtkWidget *hbox;
	GtkWidget *wbox;
	GtkWidget *notebook;
	GtkWidget *sw;
	GtkWidget *bbox, *hbbox, *add, *removew, *reloadw;
	char *modtitles[3] = { "Module", "Description", "Use Count" };
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	
	statusbar = gtk_statusbar_new();
	gtk_widget_show(statusbar);
	
	gtk_signal_connect(GTK_OBJECT(window), "delete_event",
			GTK_SIGNAL_FUNC (exit_nicely), window);
	gtk_signal_connect(GTK_OBJECT(window), "destroy",
			GTK_SIGNAL_FUNC (exit_now), window);
	gtk_container_set_border_width(GTK_CONTAINER(window), 10);

	quit = gtk_button_new_with_label("Quit Asterisk");
	gtk_signal_connect(GTK_OBJECT(quit), "clicked",
			GTK_SIGNAL_FUNC (exit_completely), window);
	gtk_widget_show(quit);

	closew = gtk_button_new_with_label("Close Window");
	gtk_signal_connect(GTK_OBJECT(closew), "clicked",
			GTK_SIGNAL_FUNC (exit_nicely), window);
	gtk_widget_show(closew);

	notebook = gtk_notebook_new();
	verb = gtk_clist_new(1);
	gtk_clist_columns_autosize(GTK_CLIST(verb));
	sw = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
	gtk_container_add(GTK_CONTAINER(sw), verb);
	gtk_widget_show(verb);
	gtk_widget_show(sw);
	gtk_widget_set_usize(verb, 640, 400);
	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, gtk_label_new("Verbose Status"));

	
	modules = gtk_clist_new_with_titles(3, modtitles);
	gtk_clist_columns_autosize(GTK_CLIST(modules));
	gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 0, TRUE);
	gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 1, TRUE);
	gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 2, TRUE);
	gtk_clist_set_sort_column(GTK_CLIST(modules), 0);
	gtk_clist_set_auto_sort(GTK_CLIST(modules), TRUE);
	gtk_clist_column_titles_passive(GTK_CLIST(modules));
	sw = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
	gtk_container_add(GTK_CONTAINER(sw), modules);
	gtk_clist_set_selection_mode(GTK_CLIST(modules), GTK_SELECTION_BROWSE);
	gtk_widget_show(modules);
	gtk_widget_show(sw);

	add = gtk_button_new_with_label("Load...");
	gtk_widget_show(add);
	removew = gtk_button_new_with_label("Unload");
	gtk_widget_show(removew);
	reloadw = gtk_button_new_with_label("Reload");
	gtk_widget_show(reloadw);
	gtk_signal_connect(GTK_OBJECT(removew), "clicked",
			GTK_SIGNAL_FUNC (remove_module), window);
	gtk_signal_connect(GTK_OBJECT(add), "clicked",
			GTK_SIGNAL_FUNC (add_module), window);
	gtk_signal_connect(GTK_OBJECT(reloadw), "clicked",
			GTK_SIGNAL_FUNC (reload_module), window);
		
	bbox = gtk_vbox_new(FALSE, 5);
	gtk_widget_show(bbox);

	gtk_widget_set_usize(bbox, 100, -1);
	gtk_box_pack_start(GTK_BOX(bbox), add, FALSE, FALSE, 5);
	gtk_box_pack_start(GTK_BOX(bbox), removew, FALSE, FALSE, 5);
	gtk_box_pack_start(GTK_BOX(bbox), reloadw, FALSE, FALSE, 5);

	hbbox = gtk_hbox_new(FALSE, 5);
	gtk_widget_show(hbbox);
	
	gtk_box_pack_start(GTK_BOX(hbbox), sw, TRUE, TRUE, 5);
	gtk_box_pack_start(GTK_BOX(hbbox), bbox, FALSE, FALSE, 5);

	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), hbbox, gtk_label_new("Module Information"));

	gtk_widget_show(notebook);

	wbox = gtk_hbox_new(FALSE, 5);
	gtk_widget_show(wbox);
	gtk_box_pack_end(GTK_BOX(wbox), quit, FALSE, FALSE, 5);
	gtk_box_pack_end(GTK_BOX(wbox), closew, FALSE, FALSE, 5);

	hbox = gtk_vbox_new(FALSE, 0);
	gtk_widget_show(hbox);
	
	/* Command line */
	cli = gtk_entry_new();
	gtk_widget_show(cli);

	gtk_signal_connect(GTK_OBJECT(cli), "activate",
			GTK_SIGNAL_FUNC (cli_activate), NULL);

	gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 5);
	gtk_box_pack_start(GTK_BOX(hbox), wbox, FALSE, FALSE, 5);
	gtk_box_pack_start(GTK_BOX(hbox), cli, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hbox), statusbar, FALSE, FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), hbox);
	gtk_window_set_title(GTK_WINDOW(window), "Asterisk Console");
	gtk_widget_grab_focus(cli);
	ast_pthread_create(&console_thread, NULL, consolethread, NULL);
	/* XXX Okay, seriously fix me! XXX */
	usleep(100000);
	ast_register_verbose(verboser);
	gtk_clist_freeze(GTK_CLIST(verb));
	ast_loader_register(mod_update);
	gtk_clist_thaw(GTK_CLIST(verb));
	gdk_input_add(clipipe[0], GDK_INPUT_READ, cliinput, NULL);
	mod_update();
	update_statusbar("Asterisk Console Ready");
	return 0;
}