示例#1
0
int main()
{
    struct nr_mgr* mgr = create_nrmgr(512, 1, 28, 1024, (pfn_logicmsg)my_msghandle, check_packet);
    thread_new(printf_thread, NULL);
    thread_new(listen_thread, mgr);
    
    while(true)
    {
        nr_mgr_logicmsg_handle(mgr);
        thread_sleep(1);
    }
    return 0;
}
示例#2
0
int session_mgr_start(session_mgr_t *mgr)
{
	if (mgr == NULL) {
		LOG_ERROR("Invalid session mgr");
		return ZISS_ERROR;
	}

	int is_ok = ZISS_ERROR;
	do {
		if (thread_new(&mgr->thread) == ZISS_ERROR) {
			LOG_ERROR("Fail to new thread");
			break;
		}

		if (cond_new(&mgr->exit_cond) == ZISS_ERROR) {
			LOG_ERROR("Fail to new cond");
			break;
		}

		if (thread_start(mgr->thread, _session_mgr_thread, mgr) == ZISS_ERROR) {
			cond_delete(mgr->exit_cond);
			LOG_ERROR("Fail to start thread");
			break;
		}

		is_ok = ZISS_OK;
	} while (0);

	if (is_ok == ZISS_ERROR) {
		session_mgr_stop(mgr);
	}

	return is_ok;
}
示例#3
0
static void
dbgsh (void)
{
	ulong rbx;
	int b;

	if (!config.vmm.dbgsh)
		return;
	spinlock_lock (&dbgsh_lock);
	if (!i) {
		tid = thread_new (dbgsh_thread, NULL, VMM_STACKSIZE);
		i = true;
	}
	spinlock_unlock (&dbgsh_lock);
	current->vmctl.read_general_reg (GENERAL_REG_RBX, &rbx);
	b = (int)rbx;
	if (b != -1) {
		r = b;
		s = -1;
#ifndef FWDBG
		spinlock_lock (&dbgsh_lock2);
		if (stopped)
			thread_wakeup (tid);
		spinlock_unlock (&dbgsh_lock2);
#endif
	}
	current->vmctl.write_general_reg (GENERAL_REG_RAX, (ulong)s);
}
示例#4
0
bool hci_inject_open(const hci_t *hci_interface) {
  assert(listen_socket == NULL);
  assert(thread == NULL);
  assert(clients == NULL);
  assert(hci_interface != NULL);

  hci = hci_interface;

  thread = thread_new("hci_inject");
  if (!thread)
    goto error;

  clients = list_new(client_free);
  if (!clients)
    goto error;

  listen_socket = socket_new();
  if (!listen_socket)
    goto error;

  if (!socket_listen(listen_socket, LISTEN_PORT))
    goto error;

  socket_register(listen_socket, thread_get_reactor(thread), NULL, accept_ready, NULL);
  return true;

error:;
  interface.close();
  return false;
}
示例#5
0
文件: OSMacOSX.c 项目: romburner/XML
/*++
 ********************************************************************************
 
 FUNCTION:
 
 DESCRIPTION:
 
 ARGUMENTS:
 
 RETURNS:
 
 ********************************************************************************
 --*/
void *iThread(void *code, void* data)
{
	void *handle = 0;
	thread_new(code, data);
//    void * handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)code, data, 0, NULL);
    return handle;
}
示例#6
0
int zsp_listener_start(zsp_listener_t *listener, int port)
{
	if (listener == NULL || port <= 0)
		return SSS_ERROR;

	int is_ok = SSS_ERROR;
	do
	{
		if (socket_new(&listener->sock, SOCKET_TCP_TYPE) == SSS_ERROR)
			break;

		if (thread_new(&listener->thread) == SSS_ERROR)
			break;

		listener->port = port;
		if (socket_bind(listener->sock, port) == SSS_ERROR)
			break;

		if (socket_listen(listener->sock) == SSS_ERROR)
			break;

		thread_set_interval_time(listener->thread, 0);
		if (thread_start(listener->thread, _zsp_listener_thread, listener) == SSS_ERROR)
			break;

		is_ok = SSS_OK;
	} while (0);

	if (is_ok == SSS_ERROR)
	{
		zsp_listener_stop(listener);
	}

	return is_ok;
}
示例#7
0
/**
 * Internally used helper function that creates a "receive status" thread which
 * will call the passed callback function when a status is received.
 *
 * If async is 0 no thread will be created and the command will run
 * synchronously until it completes or an error occurs.
 *
 * @param client The connected installation proxy client
 * @param command Operation name. Will be passed to the callback function
 *        in async mode or shown in debug messages in sync mode.
 * @param async A boolean indicating if receive loop should be run
 *        asynchronously or block.
 * @param status_cb Pointer to a callback function or NULL.
 * @param user_data Callback data passed to status_cb.
 *
 * @return INSTPROXY_E_SUCCESS when the thread was created (async mode), or
 *         when the command completed successfully (sync).
 *         An INSTPROXY_E_* error value is returned if an error occured.
 */
static instproxy_error_t instproxy_receive_status_loop_with_callback(instproxy_client_t client, plist_t command, instproxy_command_type_t async, instproxy_status_cb_t status_cb, void *user_data)
{
	if (!client || !client->parent || !command) {
		return INSTPROXY_E_INVALID_ARG;
	}

	if (client->receive_status_thread) {
		return INSTPROXY_E_OP_IN_PROGRESS;
	}

	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR;
	if (async == INSTPROXY_COMMAND_TYPE_ASYNC) {
		/* async mode */
		struct instproxy_status_data *data = (struct instproxy_status_data*)malloc(sizeof(struct instproxy_status_data));
		if (data) {
			data->client = client;
			data->command = plist_copy(command);
			data->cbfunc = status_cb;
			data->user_data = user_data;

			if (thread_new(&client->receive_status_thread, instproxy_receive_status_loop_thread, data) == 0) {
				res = INSTPROXY_E_SUCCESS;
			}
		}
	} else {
		/* sync mode as a fallback */
		res = instproxy_receive_status_loop(client, command, status_cb, user_data);
	}

	return res;
}
示例#8
0
文件: zlog.c 项目: rocflyhi/glow
int init_zlog(const char *file_prefix, unsigned int file_max_size)
{
    if (file_prefix == NULL || file_max_size == 0) {
        printf("illegal param.\n");
        return S_ERROR;
    }

    memset(&gs_zlog, 0, sizeof(gs_zlog));
    if (new_copy_str(&gs_zlog.file_prefix, file_prefix, NULL) != S_OK) {
        printf("fail to copy file_prefix.\n");
        return S_ERROR;
    }
    gs_zlog.file_max_size = file_max_size;

    gs_zlog.is_to_exit = FALSE;
    if (thread_new(&gs_zlog.thread) != S_OK
            || mutex_new(&gs_zlog.mutex) != S_OK
            || sema_new(&gs_zlog.sema, 0) != S_OK) {
        printf("fail to new thread.\n");
        return S_ERROR;
    }

    if (thread_start(gs_zlog.thread, _thread_zlog_do, NULL) != S_OK) {
        printf("fail to start thread.\n");
        return S_ERROR;
    }

    return S_OK;
}
示例#9
0
int
main(int argc, char **argv)
{
  thread_t *threads[2];
  list_t   *l;

  l = list_new(&g_long_op);
  threads[0] = thread_new(NULL, _routine_insert0, (void *) l);
  threads[1] = thread_new(NULL, _routine_insert1, (void *) l);
  thread_start(threads[0]);
  thread_start(threads[1]);
  thread_destroy(threads[0], 1);
  thread_destroy(threads[1], 1);

  list_destroy(l);
  return EXIT_SUCCESS;
}
示例#10
0
static void
telnet_dbgsh_init (void)
{
	if (config.vmm.telnet_dbgsh) {
		telnet_server_init ("dbgsh");
		thread_new (telnet_dbgsh_thread, NULL, VMM_STACKSIZE);
	}
}
static int init(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr)
{
    int result;

    ALOGI("init");

    if (p_cb == NULL)
    {
        ALOGE("init failed with no user callbacks!");
        return BT_HC_STATUS_FAIL;
    }

    hc_cb.epilog_timer_created = false;
    fwcfg_acked = false;
    has_cleaned_up = false;

    pthread_mutex_init(&hc_cb.worker_thread_lock, NULL);

    /* store reference to user callbacks */
    bt_hc_cbacks = (bt_hc_callbacks_t *) p_cb;

    vendor_open(local_bdaddr);

    utils_init();
#ifdef HCI_USE_MCT
    extern tHCI_IF hci_mct_func_table;
    p_hci_if = &hci_mct_func_table;
#else
    extern tHCI_IF hci_h4_func_table;
    p_hci_if = &hci_h4_func_table;
#endif

    p_hci_if->init();

    userial_init();
    lpm_init();

    utils_queue_init(&tx_q);

    if (hc_cb.worker_thread)
    {
        ALOGW("init has been called repeatedly without calling cleanup ?");
    }

    // Set prio here and let hci worker thread inherit prio
    // remove once new thread api (thread_set_priority() ?)
    // can switch prio
    raise_priority_a2dp(TASK_HIGH_HCI_WORKER);

    hc_cb.worker_thread = thread_new("bt_hc_worker");
    if (!hc_cb.worker_thread) {
        ALOGE("%s unable to create worker thread.", __func__);
        return BT_HC_STATUS_FAIL;
    }

    return BT_HC_STATUS_SUCCESS;
}
示例#12
0
eager_reader_t *eager_reader_new(
    int fd_to_read,
    const allocator_t *allocator,
    size_t buffer_size,
    size_t max_buffer_count,
    const char *thread_name) {

  assert(fd_to_read != INVALID_FD);
  assert(allocator != NULL);
  assert(buffer_size > 0);
  assert(max_buffer_count > 0);
  assert(thread_name != NULL && *thread_name != '\0');

  eager_reader_t *ret = osi_calloc(sizeof(eager_reader_t));
  if (!ret) {
    LOG_ERROR(LOG_TAG, "%s unable to allocate memory for new eager_reader.", __func__);
    goto error;
  }

  ret->allocator = allocator;
  ret->inbound_fd = fd_to_read;

  ret->bytes_available_fd = eventfd(0, 0);
  if (ret->bytes_available_fd == INVALID_FD) {
    LOG_ERROR(LOG_TAG, "%s unable to create output reading semaphore.", __func__);
    goto error;
  }

  ret->buffer_size = buffer_size;

  ret->buffers = fixed_queue_new(max_buffer_count);
  if (!ret->buffers) {
    LOG_ERROR(LOG_TAG, "%s unable to create buffers queue.", __func__);
    goto error;
  }

  ret->inbound_read_thread = thread_new(thread_name);
  if (!ret->inbound_read_thread) {
    LOG_ERROR(LOG_TAG, "%s unable to make reading thread.", __func__);
    goto error;
  }

  ret->inbound_read_object = reactor_register(
    thread_get_reactor(ret->inbound_read_thread),
    fd_to_read,
    ret,
    inbound_data_waiting,
    NULL
  );

  return ret;

error:;
  eager_reader_free(ret);
  return NULL;
}
示例#13
0
文件: thread.c 项目: mtmiron/toi
VALUE
push_scope()
{
	VALUE thr;

	thr = thread_new();
	cur_thr = thr;

	return thr;
}
示例#14
0
文件: main.c 项目: Alexis211/Grapes
int main() {
	c_logSvc("Hi world from unregistered test module !", LL_NOTICE);
	c_registerSvc("test");
	c_logSvc("Creating new thread...", LL_STATUS);
	thread_new(thread2, 0);
	c_logSvc("{1} Sending a test message to manager", LL_STATUS);
	c_nothing(1, 0);

	c_logSvc("{1} Thread now sleeping...", LL_WARNING);
	while (1) thread_sleep(1000);
	return 0;
}
示例#15
0
void module_start_up_callbacked_wrapper(
    const module_t *module,
    thread_t *callback_thread,
    thread_fn callback) {
  callbacked_wrapper_t *wrapper = osi_calloc(sizeof(callbacked_wrapper_t));

  wrapper->module = module;
  wrapper->lifecycle_thread = thread_new("module_wrapper");
  wrapper->callback_thread = callback_thread;
  wrapper->callback = callback;

  // Run the actual module start up
  thread_post(wrapper->lifecycle_thread, run_wrapped_start_up, wrapper);
}
示例#16
0
static void
vmmcall_dbgsh_init_pcpu (void)
{
#ifdef FWDBG
	char buf[100];

	spinlock_lock (&dbgsh_lock);
	if (!i) {
		snprintf (buf, 100, "dbgsh:s=%p,r=%p\n", &s, &r);
		debug_addstr (buf);
		thread_new (dbgsh_thread, NULL, PAGESIZE);
		i = true;
	}
	spinlock_unlock (&dbgsh_lock);
#endif
}
示例#17
0
bt_status_t btif_sock_init(void) {
  assert(thread_handle == -1);
  assert(thread == NULL);

  btsock_thread_init();
  thread_handle = btsock_thread_create(btsock_signaled, NULL);
  if (thread_handle == -1) {
    LOG_ERROR("%s unable to create btsock_thread.", __func__);
    goto error;
  }

  bt_status_t status = btsock_rfc_init(thread_handle);
  if (status != BT_STATUS_SUCCESS) {
    LOG_ERROR("%s error initializing RFCOMM sockets: %d", __func__, status);
    goto error;
  }

  status = btsock_l2cap_init(thread_handle);
  if (status != BT_STATUS_SUCCESS) {
    LOG_ERROR("%s error initializing L2CAP sockets: %d", __func__, status);
    goto error;
  }

  thread = thread_new("btif_sock");
  if (!thread) {
    LOG_ERROR("%s error creating new thread.", __func__);
    btsock_rfc_cleanup();
    goto error;
  }

  status = btsock_sco_init(thread);
  if (status != BT_STATUS_SUCCESS) {
    LOG_ERROR("%s error initializing SCO sockets: %d", __func__, status);
    btsock_rfc_cleanup();
    goto error;
  }

  return BT_STATUS_SUCCESS;

error:;
  thread_free(thread);
  thread = NULL;
  if (thread_handle != -1)
    btsock_thread_exit(thread_handle);
  thread_handle = -1;
  return BT_STATUS_FAIL;
}
示例#18
0
文件: thread_t.c 项目: noelbk/bklib
int main() {
    thread_t *th[N];
    int i;
    void *ret;

    for(i=0; i<N; i++) {
	th[i] = thread_new(thfunc, (void*)(intptr_t)i);
    }

    for(i=0; i<N; i++) {
	thread_join(th[i], &ret);
	printf("joined thread i=%d ret=%p\n", i, ret);
	thread_detach(th[i]);
    }

    return 0;
}
示例#19
0
void process_start(Process* proc) {
    MAGIC_ASSERT(proc);

    /* dont do anything if we are already running */
    if(!process_isRunning(proc)) {
        info("starting '%s' process", g_quark_to_string(proc->programID));

        /* need to get thread-private program from current worker */
        proc->prog = worker_getPrivateProgram(proc->programID);
        proc->mainThread = thread_new(proc, proc->prog);

        /* make sure the plugin registered before getting our program state */
        if(!program_isRegistered(proc->prog)) {
//            program_swapInState(proc->prog, proc->state);
            thread_executeInit(proc->mainThread, program_getInitFunc(proc->prog));
//            program_swapOutState(proc->prog, proc->state);

            if(!program_isRegistered(proc->prog)) {
                error("The plug-in '%s' must call shadowlib_register()", program_getName(proc->prog));
            }
        }

        /* create our default state as we run in our assigned worker */
        proc->state = program_newDefaultState(proc->prog);

        /* get arguments from the configured software */
        gchar** argv;
        gint argc = _process_getArguments(proc, &argv);

        /* we will need to free each argument, copy argc in case they change it */
        gint n = argc;

        /* now we will execute in the plugin */
        program_swapInState(proc->prog, proc->state);
        thread_executeNew(proc->mainThread, program_getNewFunc(proc->prog), argc, argv);
        program_swapOutState(proc->prog, proc->state);

        /* free the arguments */
        for(gint i = 0; i < n; i++) {
            g_free(argv[i]);
        }
        g_free(argv);
    }
}
示例#20
0
文件: thread.c 项目: mtmiron/toi
void
Init_thread()
{
	if (!thr_stk)
		thr_stk = vector_new();
	if (!cur_thr)
		cur_thr = thread_new();

	cThread = define_class(intern("Thread"), cObject);
	OBJ_SETUP(cur_thr, T_THREAD);
	BASIC(cur_thr).klass = cThread;
	define_method(cThread, intern("call"), eval_thread, 1);

	define_singleton_method(cThread, intern("main"), main_thread, 0);
	define_singleton_method(cThread, intern("current"), thread_s_current, 0);
	define_singleton_method(cThread, intern("critical"), thread_get_critical, 0);
	define_singleton_method(cThread, intern("setcritical"), thread_set_critical, 1);

}
示例#21
0
static int
dbgsh_enabled (int b)
{
	spinlock_lock (&dbgsh_lock);
	if (!i) {
		tid = thread_new (dbgsh_thread, NULL, VMM_STACKSIZE);
		i = true;
	}
	spinlock_unlock (&dbgsh_lock);
	if (b != -1) {
		r = b;
		s = -1;
		spinlock_lock (&dbgsh_lock2);
		if (stopped)
			thread_wakeup (tid);
		spinlock_unlock (&dbgsh_lock2);
	}
	return s;
}
示例#22
0
文件: tls_user.c 项目: regit/nufw
void tls_user_servers_init()
{
    /* init sasl stuff */
    my_sasl_init();

    init_client_struct();

    /* pre client list */
    pre_client_list = NULL;

    thread_new(&nuauthdatas->pre_client_thread,
               "pre client thread", pre_client_check);

    /* create tls sasl worker thread pool */
    nuauthdatas->tls_sasl_worker =
        g_thread_pool_new((GFunc) tls_sasl_connect, NULL,
                          nuauthconf->nb_auth_checkers, FALSE,
                          NULL);
}
示例#23
0
void processor_io_single(struct connection *con,  struct processor_data *pd, void *data, int size, enum bistream_direction direction)
{
//	g_warning("%s con %p pd %p data %p size %i dir %i", __PRETTY_FUNCTION__, con, pd, data, size, direction);

	processor_io io = NULL;
	GFunc thread_io = NULL;

	if( direction ==  bistream_in )
	{
		if( (io = pd->processor->io_in) == NULL)
			thread_io = processors_io_in_thread;
	}else
	{
		if( (io = pd->processor->io_out) == NULL)
			thread_io = processors_io_out_thread;
	}

//	g_warning("processor %s io %p thread_io %p", pd->processor->name, io, thread_io);

	if( thread_io != NULL )
	{
		struct bistream *bistream = pd->bistream;
		bistream_data_add(bistream, direction, data, size);

		g_mutex_lock(&pd->queued.mutex);
		if( pd->queued.refs == 0 )
		{
			pd->queued.refs++;
			GError *thread_error;
			struct thread *t = thread_new(con, pd, thread_io);

			connection_ref(con);
			g_thread_pool_push(g_dionaea->threads->pool, t, &thread_error);
		}
		g_mutex_unlock(&pd->queued.mutex);
	}else
	if( io != NULL )
	{
		io(con, pd, data, size);
	}
}
示例#24
0
/*
---------------------------------------
    打开 UDPv4 通讯接口
---------------------------------------
*/
static bool_t
qst_com_udpv4 (
  __CR_IN__ void_t*     parm,
  __CR_IN__ uint_t      argc,
  __CR_IN__ ansi_t**    argv
    )
{
    uint_t      port;
    socket_t    netw;

    /* 参数解析 <目标地址> <端口号> */
    if (argc < 3)
        return (FALSE);
    port = str2intxA(argv[2]);
    if (port > 65535)
        return (FALSE);

    sQstComm*   ctx = (sQstComm*)parm;

    /* 关闭当前接口并打开 UDPv4 连接 */
    netw = client_udp_open(argv[1], (int16u)port);
    if (netw == NULL)
        return (FALSE);
    socket_set_timeout(netw, QCOM_SNDTOUT, QCOM_CUTDOWN);

    /* 设置工作参数 */
    qst_com_close(parm, argc, argv);
    ctx->comm.obj.netw = netw;
    ctx->comm.send = qst_udpv4_send;

    /* 启动接收线程 */
    ctx->comm.thrd = thread_new(0, qst_udpv4_main, parm, FALSE);
    if (ctx->comm.thrd == NULL) {
        socket_close(netw);
        return (FALSE);
    }
    TRY_FREE(ctx->comm.title);
    ctx->comm.title = str_fmtA(" - UDPv4 \"%s\", %u", argv[1], port);
    qst_update_title(ctx);
    return (TRUE);
}
示例#25
0
文件: linux.c 项目: Laukien/test
int main() {
	THREAD *t = thread_new();
	thread_setFunction(t, sub, NULL);
	thread_run(t);

	int i;
	for (i = 0; i < 10; ++i) {
		if (thread_isRunning(t)) {
			printf ("Thread 1 is still running\n");
			sleep(1);
		}
	}

	thread_wait(t);

	printf("Thread 1 has the status %d\n", thread_getStatus(t));

	printf("Thread 1 has the exit-code %d\n", thread_getExit(t));

	thread_free(t);
	return EXIT_SUCCESS;
}
示例#26
0
int zfp_transport_new(zfp_transport_t **ptransport, session_id_t session)
{
	if (ptransport == NULL)
		return ZISS_ERROR;

	zfp_transport_t *new_transport = (zfp_transport_t*)malloc(sizeof(zfp_transport_t));
	if (new_transport == NULL) {
		LOG_ERROR("Fail to malloc");
		return ZISS_ERROR;
	}
	memset(new_transport, 0, sizeof(zfp_transport_t));
	new_transport->session = session;
	
	if (thread_new(&new_transport->thread) == ZISS_ERROR) {
		LOG_ERROR("Fail to new thread");
		free(new_transport);
		new_transport = NULL;
		return ZISS_ERROR;
	}

	*ptransport = new_transport;
	return ZISS_OK;
}
示例#27
0
static bool lazy_initialize(void) {
  assert(alarms == NULL);

  pthread_mutex_init(&monitor, NULL);

  alarms = list_new(NULL);
  if (!alarms) {
    LOG_ERROR("%s unable to allocate alarm list.", __func__);
    return false;
  }

  struct sigevent sigevent;
  memset(&sigevent, 0, sizeof(sigevent));
  sigevent.sigev_notify = SIGEV_THREAD;
  sigevent.sigev_notify_function = (void (*)(union sigval))timer_callback;
  if (timer_create(CLOCK_ID, &sigevent, &timer) == -1) {
    LOG_ERROR("%s unable to create timer: %s", __func__, strerror(errno));
    return false;
  }

  alarm_expired = semaphore_new(0);
  if (!alarm_expired) {
    LOG_ERROR("%s unable to create alarm expired semaphore", __func__);
    return false;
  }

  callback_thread_active = true;
  callback_thread = thread_new("alarm_callbacks");
  if (!callback_thread) {
    LOG_ERROR("%s unable to create alarm callback thread.", __func__);
    return false;
  }

  thread_set_priority(callback_thread, CALLBACK_THREAD_PRIORITY_HIGH);
  thread_post(callback_thread, callback_dispatch, NULL);
  return true;
}
示例#28
0
/*
---------------------------------------
    启动一个工作单元
---------------------------------------
*/
static bool_t
qst_wrk_wakeup (
  __CR_IO__ sQstWork*   work,
  __CR_IN__ ansi_t*     name,
  __CR_IN__ socket_t    netw,
  __CR_IN__ mt_main_t   proc
    )
{
    thrd_t  thrd;
    uint_t  count;

    /* 查找空闲单元 */
    count = work[0].cnt;
    for (uint_t idx = 0; idx < count; idx++) {
        if (work[idx].over) {
            if (!netw_ack_send(netw, TRUE))
                return (FALSE);
            thrd = thread_new(0, proc, &work[idx], TRUE);
            if (thrd == NULL)
                return (FALSE);
            work[idx].name = name;
            work[idx].netw = netw;
            work[idx].over = FALSE;
            if (thread_goon(thrd))
            {
                /* 显示已经连线 */
                _ENTER_SHOW_CIN_
                printf("[%s] is online.\n", name);
                _LEAVE_SHOW_CIN_
            }
            thread_del(thrd);
            return (TRUE);
        }
    }
    netw_ack_send(netw, FALSE);
    return (FALSE);
}
LIBIMOBILEDEVICE_API np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, void *user_data )
{
	if (!client)
		return NP_E_INVALID_ARG;

	np_error_t res = NP_E_UNKNOWN_ERROR;

	np_lock(client);
	if (client->notifier) {
		debug_info("callback already set, removing");
		property_list_service_client_t parent = client->parent;
		client->parent = NULL;
		thread_join(client->notifier);
		thread_free(client->notifier);
		client->notifier = (thread_t)NULL;
		client->parent = parent;
	}

	if (notify_cb) {
		struct np_thread *npt = (struct np_thread*)malloc(sizeof(struct np_thread));
		if (npt) {
			npt->client = client;
			npt->cbfunc = notify_cb;
			npt->user_data = user_data;

			if (thread_new(&client->notifier, np_notifier, npt) == 0) {
				res = NP_E_SUCCESS;
			}
		}
	} else {
		debug_info("no callback set");
	}
	np_unlock(client);

	return res;
}
示例#30
0
void
gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, char *extensions,
						int flags)
{
	struct file_req *freq;
	GtkWidget *dialog;
	GtkFileFilter *filefilter;
	extern char *get_xdir_fs (void);
	char *token;
	char *tokenbuffer;

#if 0	/* native file dialogs */
#ifdef WIN32
	if (!(flags & FRF_WRITE))
	{
		freq = malloc (sizeof (struct file_req));
		freq->th = thread_new ();
		freq->flags = 0;
		freq->multiple = (flags & FRF_MULTIPLE);
		freq->callback = callback;
		freq->userdata = userdata;
		freq->title = g_locale_from_utf8 (title, -1, 0, 0, 0);
		if (!filter)
		{
			freq->filter =	"All files\0*.*\0"
							"Executables\0*.exe\0"
							"ZIP files\0*.zip\0\0";
		}
		else
		{
			freq->filter = filter;
		}

		thread_start (freq->th, win32_thread, freq);
		fe_input_add (freq->th->pipe_fd[0], FIA_FD|FIA_READ, win32_read_thread, freq);

		return;

	}
	
	else {
		freq = malloc (sizeof (struct file_req));
		freq->th = thread_new ();
		freq->flags = 0;
		freq->multiple = (flags & FRF_MULTIPLE);
		freq->callback = callback;
		freq->userdata = userdata;
		freq->title = g_locale_from_utf8 (title, -1, 0, 0, 0);
		if (!filter)
		{
			freq->filter = "All files\0*.*\0\0";
		}
		else
		{
			freq->filter = filter;
		}

		thread_start (freq->th, win32_thread2, freq);
		fe_input_add (freq->th->pipe_fd[0], FIA_FD|FIA_READ, win32_read_thread, freq);

	return;
	}
#endif
#endif

	if (flags & FRF_WRITE)
	{
		dialog = gtk_file_chooser_dialog_new (title, NULL,
												GTK_FILE_CHOOSER_ACTION_SAVE,
												GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
												GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
												NULL);
		if (filter && filter[0])	/* filter becomes initial name when saving */
		{
			char temp[1024];
			path_part (filter, temp, sizeof (temp));
			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), temp);
			gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), file_part (filter));
		}

		if (!(flags & FRF_NOASKOVERWRITE))
			gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
	}
	else
		dialog = gtk_file_chooser_dialog_new (title, NULL,
												GTK_FILE_CHOOSER_ACTION_OPEN,
												GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
												GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
												NULL);
	if (flags & FRF_MULTIPLE)
		gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
	if (last_dir[0])
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir);
	if (flags & FRF_ADDFOLDER)
		gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
														  get_xdir_fs (), NULL);
	if (flags & FRF_CHOOSEFOLDER)
	{
		gtk_file_chooser_set_action (GTK_FILE_CHOOSER (dialog), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), filter);
	}
	else
	{
		if (filter && (flags & FRF_FILTERISINITIAL))
			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), filter);
	}

	if (flags & FRF_EXTENSIONS && extensions != NULL)
	{
		filefilter = gtk_file_filter_new ();
		tokenbuffer = g_strdup (extensions);
		token = strtok (tokenbuffer, ";");

		while (token != NULL)
		{
			gtk_file_filter_add_pattern (filefilter, token);
			token = strtok (NULL, ";");
		}

		g_free (tokenbuffer);
		gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filefilter);
	}

	freq = malloc (sizeof (struct file_req));
	freq->dialog = dialog;
	freq->flags = flags;
	freq->callback = callback;
	freq->userdata = userdata;

	g_signal_connect (G_OBJECT (dialog), "response",
							G_CALLBACK (gtkutil_file_req_response), freq);
	g_signal_connect (G_OBJECT (dialog), "destroy",
						   G_CALLBACK (gtkutil_file_req_destroy), (gpointer) freq);
	gtk_widget_show (dialog);
}