PageRenderTime 274ms CodeModel.GetById 166ms app.highlight 9ms RepoModel.GetById 97ms app.codeStats 0ms

/fbus/demo/fbus_echo.c

http://ftk.googlecode.com/
C | 148 lines | 93 code | 26 blank | 29 comment | 35 complexity | 4da7f37570f4b8a01d26f07cf4554fe4 MD5 | raw file
  1/*
  2 * File:    fbus_echo.c
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   echo client api.
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2010-07-25 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#include "fbus_echo.h"
 33#include "fbus_echo_common.h"
 34
 35FBusEcho* fbus_echo_create()
 36{
 37	return fbus_proxy_create(FBUS_SERVICE_ECHO);	
 38}
 39
 40Ret fbus_echo_char(FBusEcho* thiz, char in, char* out)
 41{
 42	Ret ret = RET_FAIL;
 43	FBusParcel* parcel = fbus_proxy_get_parcel(thiz);
 44	return_val_if_fail(parcel != NULL && out != NULL, RET_FAIL);
 45
 46	fbus_parcel_write_int(parcel, FBUS_ECHO_CHAR);
 47	fbus_parcel_write_char(parcel, in);
 48	
 49	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
 50	{
 51		if((ret = fbus_parcel_get_int(parcel)) == RET_OK)
 52		{
 53			*out = fbus_parcel_get_char(parcel);
 54		}
 55	}
 56
 57	return ret;
 58}
 59
 60Ret fbus_echo_short(FBusEcho* thiz, short in, short* out)
 61{
 62	Ret ret = RET_FAIL;
 63	FBusParcel* parcel = fbus_proxy_get_parcel(thiz);
 64	return_val_if_fail(parcel != NULL && out != NULL, RET_FAIL);
 65
 66	fbus_parcel_write_int(parcel, FBUS_ECHO_SHORT);
 67	fbus_parcel_write_short(parcel, in);
 68	
 69	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
 70	{
 71		if((ret = fbus_parcel_get_int(parcel)) == RET_OK)
 72		{
 73			*out = fbus_parcel_get_short(parcel);
 74		}
 75	}
 76
 77	return ret;
 78}
 79
 80Ret fbus_echo_int(FBusEcho* thiz, int in, int* out)
 81{
 82	Ret ret = RET_FAIL;
 83	FBusParcel* parcel = fbus_proxy_get_parcel(thiz);
 84	return_val_if_fail(parcel != NULL && out != NULL, RET_FAIL);
 85
 86	fbus_parcel_write_int(parcel, FBUS_ECHO_INT);
 87	fbus_parcel_write_int(parcel, in);
 88	
 89	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
 90	{
 91		if((ret = fbus_parcel_get_int(parcel)) == RET_OK)
 92		{
 93			*out = fbus_parcel_get_int(parcel);
 94		}
 95	}
 96
 97	return ret;
 98}
 99
100Ret fbus_echo_string(FBusEcho* thiz, const char* in, const char** out)
101{
102	Ret ret = RET_FAIL;
103	FBusParcel* parcel = fbus_proxy_get_parcel(thiz);
104	return_val_if_fail(parcel != NULL && out != NULL, RET_FAIL);
105
106	fbus_parcel_write_int(parcel, FBUS_ECHO_STRING);
107	fbus_parcel_write_string(parcel, in);
108	
109	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
110	{
111		if((ret = fbus_parcel_get_int(parcel)) == RET_OK)
112		{
113			*out = fbus_parcel_get_string(parcel);
114		}
115	}
116
117	return ret;
118}
119
120Ret fbus_echo_data(FBusEcho* thiz, const char* in, size_t in_len, const char** out, size_t* out_len)
121{
122	Ret ret = RET_FAIL;
123	FBusParcel* parcel = fbus_proxy_get_parcel(thiz);
124	return_val_if_fail(parcel != NULL && out != NULL, RET_FAIL);
125
126	fbus_parcel_write_int(parcel, FBUS_ECHO_BINARY);
127	fbus_parcel_write_int(parcel, in_len);
128	fbus_parcel_write_data(parcel, in, in_len);
129	
130	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
131	{
132		if((ret = fbus_parcel_get_int(parcel)) == RET_OK)
133		{
134			*out_len = fbus_parcel_get_data_size(parcel);
135			*out = fbus_parcel_get_data(parcel, in_len);
136		}
137	}
138
139	return ret;
140}
141
142void fbus_echo_destroy(FBusEcho* thiz)
143{
144	fbus_proxy_destroy(thiz);
145
146	return;
147}
148