コード例 #1
0
json_t* new_customer(const char* name, const char* email, const char* address,
	const char* phone, const char* gender, const char* message) {
	MYSQL_RES *res_ptr;

	char query[200];
	sprintf(query, "INSERT INTO customer (Name, Phone, Address, Email, Gender, CreatedAt, UpdatedAt) VALUES ('%s', '%s', '%s', '%s', '%s', now(), now())",
		name, phone, address, email, gender);
	printf("%s\n", query);
	res_ptr = get_data_from_database(query);

	printf("%s\n", "get_customer phone");
	return get_customer(phone);
}
コード例 #2
0
ファイル: runtime_info.hpp プロジェクト: dailypips/dcsxx-des
	/// Accumulate the effective amount of work done (the work will not be scaled)
	public: void accumulate_work2(real_type w)
	{
		// NOTE: the use of epsilon() is to take care of cancellation errors due
		//       to floating-point subtraction.

DCS_DEBUG_TRACE("(" << this << ") Accumulating work for Customer: " << ::std::setprecision(12) << get_customer() << " -> Work: " << w << " - Old Total work: " << wt_ << " - New Total work: " << (wt_+w) << " - Service Demand: " << sd_ << " - Condition: " << ::std::boolalpha << (wt_+w<=sd_) << " - Condition#2: " << ::std::boolalpha << ((wt_+w)<=sd_) << " - Condition#3: " << ::std::boolalpha << ((wt_+w)>sd_) << " - Difference: " << ((wt_+w)-sd_) << " - epsilon: " << ::std::numeric_limits<real_type>::epsilon());//XXX
		DCS_DEBUG_ASSERT( w >= 0 );
		//DCS_DEBUG_ASSERT( wt_+w <= sd_ );
		DCS_DEBUG_ASSERT( ::dcs::math::float_traits<real_type>::definitely_less_equal(wt_+w, sd_) );

		wt_ += w;
		lwut_ = -1; // not available
	}
コード例 #3
0
int main(int argc, char*argv[]) {

	char* test = (char *) malloc(500*sizeof(char));

    json_error_t error;
	json_t *root;
	json_t *data;
	json_t *j_type;
	json_t *j_data;
	json_t *phone;

	const char *type;
	const char *customer_phone;

	int server_sockfd, client_sockfd;
	int server_len, client_len;

	struct sockaddr_in server_address;
	struct sockaddr_in client_address;

	server_sockfd = socket(PF_INET, SOCK_STREAM, 0);
	server_address.sin_family = PF_INET;
	// server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
	server_address.sin_addr.s_addr = htonl(INADDR_ANY);
	server_address.sin_port = htons(9733);
	server_len = sizeof(server_address);

	bind(server_sockfd, (struct sockaddr *)&server_address, server_len);

	listen(server_sockfd, 5);

	while (1) {
		test = (char *) malloc(500*sizeof(char));
		printf("server waitting\n");
		client_len = sizeof(client_address);
		client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);
		
		read(client_sockfd, test, 500);

		root = json_loads(test, 0, &error);

		free(test);

		if(!root) {
	        fprintf(stderr, "error: on line %d: %s\n", error.line, error.text);
	        // Response error to client
			response_data(0, json_object(), client_sockfd);

    	} else {
	    	j_type = json_object_get(root, "type");
	    	j_data = json_object_get(root, "data");

	    	if (!j_type || !j_data) {
				response_data(0, json_object(), client_sockfd);

	    	} else {
	    		type = json_string_value(j_type);
		    	printf("Type: %s\n", type);
		    	if (strcmp(type, "gcustomerinfo") == 0) {
		    		const char * phone = get_value(root, "phone");
		    		json_t *data = get_customer(phone);

					response_data(1, data, client_sockfd);
		    	
		    	} else if (strcmp(type, "pcustomerinfo") == 0) {
		    		const char * name = get_value(root, "name");
		    		const char * email = get_value(root, "email");
		    		const char * address = get_value(root, "address");
		    		const char * phone = get_value(root, "phone");
		    		const char * gender = get_value(root, "gender");

		    		json_t *data = new_customer(name, email, address, phone, gender, "test");

		    		response_data(1, data, client_sockfd);

		    	} else if (strcmp(type, "ucustomerinfo") == 0) {
		    		const char * id = get_value(root, "id");
		    		const char * name = get_value(root, "name");
		    		const char * email = get_value(root, "email");
		    		const char * address = get_value(root, "address");
		    		const char * gender = get_value(root, "gender");

		    		json_t *data = update_customer(id, name, email, address, gender);

		    		response_data(1, data, client_sockfd);

		    	} else if (strcmp(type, "porder") == 0) {
		    		const char * customer_id = get_value(root, "id");
		    		const char * message = get_value(root, "message");

		    		json_t *data = new_order(customer_id, message);

		    		response_data(1, data, client_sockfd);

		    	} else if (strcmp(type, "porderdetail") == 0) {
		    		const char * order_id = get_value(root, "oid");
		    		const char * product_id = get_value(root, "pid");
		    		const char * quantity = get_value(root, "quantity");

		    		json_t *data = new_order_detail(order_id, product_id, quantity);

		    		response_data(1, data, client_sockfd);

		    	// Default
		    	} else {
		    		response_data(0, json_object(), client_sockfd);
		    	}
	    	}
    	}

		close(client_sockfd);
	}
}