Exemple #1
0
void __disconnect() {
	if (ipc_disconnect(__get_id(), SRV_ID) == OK) {
		printf("Clt: diconnected from srv\n");
	} else {
		printf("Clt: could not disconnect from srv [ERROR]\n");
	}
}
Exemple #2
0
void __connect() {
	if (ipc_connect(__get_id(), SRV_ID) == OK) {
		printf("Clt: connected to srv\n");
	} else {
		printf("Clt: could not connect to srv [ERROR]\n");
	}
}
Exemple #3
0
int __get_product(product_name name, Product * productp){
	char toSend[sizeof(product_name_msg)];
	msg_type resp_type;
	char resp_body[sizeof(product_resp)];
	
	__connect();
	msg_serialize_product_name_msg(__get_id(), GET_PRODUCT, name, toSend);
	__send(toSend, sizeof(product_name_msg));
	__recv(&resp_type, sizeof(msg_type));

	if (resp_type == OK_RESP) {
		__recv(resp_body, sizeof(Product));
		msg_deserialize_product(resp_body, productp);
		__disconnect();
		return OK;
	}
	return __handle_not_ok_resp(resp_type);
}
Exemple #4
0
int __write_product(product_name name, int quantity){
	char toSend[sizeof(product_msg)];
	msg_type resp_type;
	char resp_body[sizeof(error_resp)];
	int code;

	__connect();	
	msg_serialize_product_msg(__get_id(), WRITE_PRODUCT, product_new(name, quantity), toSend);
	__send(toSend, sizeof(product_msg));
	__recv(&resp_type, sizeof(msg_type));
	if (resp_type == OK_RESP) {
		__recv(resp_body, sizeof(int));
		msg_deserialize_code(resp_body, &code);
		__disconnect();
		return OK;
	}
	return __handle_not_ok_resp(resp_type);
}
Exemple #5
0
/* TODO: Make an async-safe alternative */
void xseg_printtrace(void)
{
	void *array[20];
	char **bt;
	size_t size;
	int i;
	pid_t tid = __get_id();

	size = backtrace(array, 20);
	bt = backtrace_symbols(array, size);
	if (!bt) {
		return;
	}

	XSEGLOG2(I, "Backtrace of tid %d:", tid);
	for (i = 0; i < size; ++i)
	{
		XSEGLOG2(I, "\t%s", bt[i]);
	}
}
Exemple #6
0
void __recv(void * buf, int len) {
	printf("Clt: read %d bytes of %d\n", ipc_recv(__get_id(), buf, len), len);
}
Exemple #7
0
void __send(void * buf, int len) {
	printf("Clt: wrote %d bytes of %d\n", ipc_send(__get_id(), SRV_ID, buf, len), len);	
}