PageRenderTime 53ms CodeModel.GetById 15ms app.highlight 32ms RepoModel.GetById 2ms app.codeStats 0ms

/fbus/fbus_service_manager.c

http://ftk.googlecode.com/
C | 197 lines | 134 code | 34 blank | 29 comment | 54 complexity | 5ca4f1ccfb6b65df9aec9b26bec94ab5 MD5 | raw file
  1/*
  2 * File:    fbus_service_manager.c 
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   client api used to access service manager.
  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_service_manager.h"
 33
 34FBusServiceManager* fbus_service_manager_create(void)
 35{
 36	return fbus_proxy_create(FBUS_SERVICE_MANAGER_NAME);
 37}
 38
 39Ret fbus_service_manager_get_nr(FBusServiceManager* thiz, int* nr)
 40{
 41	Ret ret = RET_FAIL;
 42	FBusParcel* parcel = NULL;
 43	return_val_if_fail(thiz != NULL && nr != NULL, RET_FAIL);
 44	parcel = fbus_proxy_get_parcel(thiz);
 45	return_val_if_fail(parcel != NULL, RET_FAIL);
 46
 47	fbus_parcel_write_int(parcel, FBUS_SERVICE_MANAGER_REQ_GET_NR);
 48	
 49	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
 50	{
 51		ret = fbus_parcel_get_int(parcel);
 52		if(ret == RET_OK)
 53		{
 54			*nr = fbus_parcel_get_int(parcel);	
 55		}
 56	}
 57
 58	return ret;
 59}
 60
 61Ret fbus_service_manager_get(FBusServiceManager* thiz, int i, FBusServiceInfo* info)
 62{
 63	Ret ret = RET_FAIL;
 64	FBusParcel* parcel = NULL;
 65	return_val_if_fail(thiz != NULL && info != NULL, RET_FAIL);
 66	parcel = fbus_proxy_get_parcel(thiz);
 67	return_val_if_fail(parcel != NULL, RET_FAIL);
 68
 69	fbus_parcel_write_int(parcel, FBUS_SERVICE_MANAGER_REQ_GET);
 70	fbus_parcel_write_int(parcel, i);
 71	
 72	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
 73	{
 74		ret = fbus_parcel_get_int(parcel);
 75		if(ret == RET_OK)
 76		{
 77			*info = *(FBusServiceInfo*)fbus_parcel_get_data(parcel, sizeof(FBusServiceInfo));
 78		}
 79	}
 80
 81	return ret;
 82}
 83
 84Ret fbus_service_manager_stop(FBusServiceManager* thiz, const char* name)
 85{
 86	Ret ret = RET_FAIL;
 87	FBusParcel* parcel = NULL;
 88	return_val_if_fail(thiz != NULL && name != NULL, RET_FAIL);
 89	parcel = fbus_proxy_get_parcel(thiz);
 90	return_val_if_fail(parcel != NULL, RET_FAIL);
 91
 92	fbus_parcel_write_int(parcel, FBUS_SERVICE_MANAGER_REQ_STOP);
 93	fbus_parcel_write_string(parcel, name);
 94	
 95	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
 96	{
 97		ret = fbus_parcel_get_int(parcel);
 98	}
 99
100	return ret;
101}
102
103Ret fbus_service_manager_start(FBusServiceManager* thiz, const char* name)
104{
105	Ret ret = RET_FAIL;
106	FBusParcel* parcel = NULL;
107	return_val_if_fail(thiz != NULL && name != NULL, RET_FAIL);
108	parcel = fbus_proxy_get_parcel(thiz);
109	return_val_if_fail(parcel != NULL, RET_FAIL);
110
111	fbus_parcel_write_int(parcel, FBUS_SERVICE_MANAGER_REQ_START);
112	fbus_parcel_write_string(parcel, name);
113	
114	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
115	{
116		ret = fbus_parcel_get_int(parcel);
117	}
118
119	return ret;
120}
121
122Ret fbus_service_manager_query(FBusServiceManager* thiz, const char* name, FBusServiceInfo* info)
123{
124	Ret ret = RET_FAIL;
125	FBusParcel* parcel = NULL;
126	return_val_if_fail(thiz != NULL && name != NULL && info != NULL, RET_FAIL);
127	parcel = fbus_proxy_get_parcel(thiz);
128	return_val_if_fail(parcel != NULL, RET_FAIL);
129
130	fbus_parcel_write_int(parcel, FBUS_SERVICE_MANAGER_REQ_QUERY);
131	fbus_parcel_write_string(parcel, name);
132	
133	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
134	{
135		ret = fbus_parcel_get_int(parcel);
136		if(ret == RET_OK)
137		{
138			*info = *(FBusServiceInfo*)fbus_parcel_get_data(parcel, sizeof(FBusServiceInfo));
139		}
140	}
141
142	return ret;
143}
144
145Ret fbus_service_manager_register(FBusServiceManager* thiz, const char* name, FBusServiceInfo* info)
146{
147	Ret ret = RET_FAIL;
148	FBusParcel* parcel = NULL;
149	return_val_if_fail(thiz != NULL && name != NULL && info != NULL, RET_FAIL);
150	parcel = fbus_proxy_get_parcel(thiz);
151	return_val_if_fail(parcel != NULL, RET_FAIL);
152
153	fbus_parcel_write_int(parcel, FBUS_SERVICE_MANAGER_REQ_REGISTER);
154	fbus_parcel_write_string(parcel, name);
155	fbus_parcel_write_string(parcel, FBUS_LOCALHOST);
156	fbus_parcel_write_int(parcel, getpid());
157	
158	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
159	{
160		ret = fbus_parcel_get_int(parcel);
161		if(ret == RET_OK)
162		{
163			*info = *(FBusServiceInfo*)fbus_parcel_get_data(parcel, sizeof(FBusServiceInfo));
164		}
165	}
166
167	return ret;
168}
169
170Ret fbus_service_manager_unregister(FBusServiceManager* thiz, const char* name)
171{
172	Ret ret = RET_FAIL;
173	FBusParcel* parcel = NULL;
174	return_val_if_fail(thiz != NULL && name != NULL, RET_FAIL);
175	parcel = fbus_proxy_get_parcel(thiz);
176	return_val_if_fail(parcel != NULL, RET_FAIL);
177
178	fbus_parcel_write_int(parcel, FBUS_SERVICE_MANAGER_REQ_UNREGISTER);
179	fbus_parcel_write_string(parcel, name);
180	fbus_parcel_write_string(parcel, FBUS_LOCALHOST);
181	fbus_parcel_write_int(parcel, getpid());
182
183	if((ret = fbus_proxy_request(thiz, parcel)) == RET_OK)
184	{
185		ret = fbus_parcel_get_int(parcel);
186	}
187
188	return ret;
189}
190
191void fbus_service_manager_destroy(FBusServiceManager* thiz)
192{
193	fbus_proxy_destroy(thiz);
194
195	return;
196}
197