Beispiel #1
0
static void destroy_sap_interface(void *data)
{
	struct sap_server *server = data;

	DBG("Unregistered interface %s on path %s", SAP_SERVER_INTERFACE,
								server->path);

	server_remove(server);
}
void* thr_servidora()   
{
	while (TRUE)
	{
		sem_wait(&semaforo_servidora);
		buffer*aux;
		pthread_mutex_lock(&servidor);
		char *k,*v, *a;
		k=(char*)malloc(KV_SIZE*sizeof(char));
		v=(char*)malloc(KV_SIZE*sizeof(char));
		int ir;
		int d;
		aux=bf[podeServidor].buf;
		a=aux->nomeFuncao;
		ir=aux->shardId;
		k=aux->key;
		v=aux->value;
		d=aux->dim;
		podeServidor=(podeServidor+1)%tamanho_buf;
		pthread_mutex_unlock(&servidor);
		sem_post(&semaforo_cliente);
		pthread_mutex_lock(&acesso);
		if(strcmp(a,"g")==0)
		{
 			server_get(aux, ir, k);
 		}
 		if(strcmp(a,"p")==0)
 		{
 			server_put(aux, ir, k,v);
 			insereEmFicheiro(ir,k,v);
 			
 		}
		if(strcmp(a,"r")==0){
 			server_remove(aux, ir, k);
 			removeFicheiro(ir,k);
 		}
 		if(strcmp(a,"k")==0)
 			server_getAllKeys(aux, ir, d);
 		pthread_mutex_unlock(&acesso);
		sem_post(&aux->semaforo_resposta);
 	}
 	return NULL;
}
Beispiel #3
0
int sap_server_register(const char *path, bdaddr_t *src)
{
	sdp_record_t *record = NULL;
	GError *gerr = NULL;
	GIOChannel *io;
	struct sap_server *server;

	if (sap_init() < 0) {
		error("Sap driver initialization failed.");
		return -1;
	}

	record = create_sap_record(SAP_SERVER_CHANNEL);
	if (!record) {
		error("Creating SAP SDP record failed.");
		goto sdp_err;
	}

	if (add_record_to_server(src, record) < 0) {
		error("Adding SAP SDP record to the SDP server failed.");
		sdp_record_free(record);
		goto sdp_err;
	}

	server = g_new0(struct sap_server, 1);
	server->path = g_strdup(path);
	server->record_id = record->handle;

	io = bt_io_listen(BT_IO_RFCOMM, NULL, connect_confirm_cb, server,
			NULL, &gerr,
			BT_IO_OPT_SOURCE_BDADDR, src,
			BT_IO_OPT_CHANNEL, SAP_SERVER_CHANNEL,
			BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_HIGH,
			BT_IO_OPT_MASTER, TRUE,
			BT_IO_OPT_INVALID);
	if (!io) {
		error("Can't listen at channel %d.", SAP_SERVER_CHANNEL);
		g_error_free(gerr);
		goto server_err;
	}
	server->listen_io = io;

	if (!g_dbus_register_interface(connection, server->path,
					SAP_SERVER_INTERFACE,
					server_methods, server_signals, NULL,
					server, destroy_sap_interface)) {
		error("D-Bus failed to register %s interface",
							SAP_SERVER_INTERFACE);
		goto server_err;
	}

	DBG("server %p, listen socket 0x%02x", server,
						g_io_channel_unix_get_fd(io));

	return 0;

server_err:
	server_remove(server);
sdp_err:
	sap_exit();

	return -1;
}