TSP: The Transport Sample Protocol



Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

tsp_server.c

Go to the documentation of this file.
00001 
00038 #include "tsp_sys_headers.h"
00039 
00040 /* FIXME a quoi sert ce define ? */
00041 #define PORTMAP
00042 #include <rpc/rpc.h>
00043 #include <netdb.h>
00044 #include <rpc/pmap_clnt.h>
00045 #include <stdio.h>
00046 #include <unistd.h>
00047 
00048 
00049 /* FIXME RP : beurk, RPC is compiled before CTRL could export this include, how sould I call Request Manager and GLU then ? */
00050 #include "../ctrl/tsp_provider.h"
00051 #include "../ctrl/tsp_request.h"
00052 #include "../ctrl/glue_sserver.h"
00053 
00054 #include "tsp_server.h"
00055 #include "tsp_rpc.h"
00056 #include "tsp_rpc_confprogid.h"
00057 
00058 void
00059 tsp_rpc_1(struct svc_req *rqstp, register SVCXPRT *transp) ;
00060 
00061 
00062 #ifndef TSP_RPC_CLEANUP
00063 
00064 #define TSP_URL_MAXLENGTH 256
00065 
00066 typedef struct {
00067   int  server_number;
00068   char url[TSP_URL_MAXLENGTH];
00069   SVCXPRT *xprt;
00070 } TSP_rpc_request_config_t;
00071 
00072 TSP_provider_info_t* tsp_provider_information_1_svc(struct svc_req *rqstp)
00073 {
00074   static TSP_provider_info_t server_info;       
00075   STRACE_IO(("-->IN"));    
00076   server_info.info = GLU_get_server_name();    
00077   STRACE_IO(("-->OUT"));
00078   return &server_info;
00079 }
00080 
00081 TSP_answer_open_t* tsp_request_open_1_svc(TSP_request_open_t req_open, struct svc_req* rqstp)
00082 {
00083 
00084   static TSP_answer_open_t ans_open;
00085         
00086   STRACE_IO(("-->IN")); 
00087   TSP_provider_request_open(&req_open, &ans_open);      
00088   STRACE_IO(("-->OUT"));        
00089   return &ans_open;
00090 
00091 }
00092 
00093 void *tsp_request_close_1_svc(TSP_request_close_t req_close, struct svc_req * rqstp)
00094 {
00095 
00096   static char* dummy;
00097         
00098   STRACE_IO(("-->IN"));
00099 
00100   TSP_provider_request_close(&req_close);
00101         
00102   STRACE_IO(("-->OUT"));
00103  
00104   return ((void*) &dummy);
00105 }
00106 
00107 TSP_answer_sample_t* tsp_request_information_1_svc(TSP_request_information_t req_info, struct svc_req * rqstp)
00108 {
00109 
00110   static TSP_answer_sample_t ans_sample;
00111         
00112   STRACE_IO(("-->IN")); 
00113   TSP_provider_request_information(&req_info, &ans_sample);
00114   STRACE_IO(("-->OUT"));       
00115   return &ans_sample;
00116 
00117 }
00118 
00119 TSP_answer_feature_t* tsp_request_feature_1_svc(TSP_request_feature_t req_feature, struct svc_req * rqstp)
00120 {
00121 
00122   static TSP_answer_feature_t ans_feature;
00123         
00124   STRACE_IO(("-->IN"));
00125   STRACE_IO(("-->OUT"));
00126         
00127   return &ans_feature;
00128 
00129 }
00130 
00131 TSP_answer_sample_t* tsp_request_sample_1_svc(TSP_request_sample_t req_sample, struct svc_req * rqstp)
00132 {
00133 
00134   static int first_call = TRUE;
00135   static TSP_answer_sample_t ans_sample;
00136 
00137   STRACE_IO(("-->IN"));
00138   /* For each call memory was allocate by TSP_provider_request_sample */
00139   if(!first_call)
00140     {
00141       TSP_provider_request_sample_free_call(&ans_sample);    
00142     }
00143   first_call = FALSE;
00144 
00145   TSP_provider_request_sample(&req_sample, &ans_sample);
00146 
00147   STRACE_IO(("-->OUT"));
00148         
00149   return &ans_sample;
00150 
00151 }
00152  
00153 TSP_answer_sample_init_t* tsp_request_sample_init_1_svc(TSP_request_sample_init_t req_sample, struct svc_req * rqstp)
00154 {
00155 
00156   static TSP_answer_sample_init_t ans_sample;
00157 
00158   STRACE_IO(("-->IN"));
00159     
00160   /*TBD FIXME Desallouer l'appel precedent*/
00161   /*if( 0 != ans_sample)
00162     {
00163     TSP_session_free_create_symbols_table_call(&ans_sample);
00164     }*/
00165     
00166   TSP_provider_request_sample_init(&req_sample, &ans_sample);
00167   STRACE_IO(("-->OUT"));
00168 
00169   return &ans_sample;
00170 
00171 }
00172 
00173 TSP_answer_sample_destroy_t* tsp_request_sample_destroy_1_svc(TSP_request_sample_destroy_t req_sample, struct svc_req * rqstp)
00174 {
00175 
00176   static TSP_answer_sample_destroy_t ans_sample;
00177         
00178   STRACE_IO(("-->IN"));
00179   TSP_provider_request_sample_destroy(&req_sample, &ans_sample);
00180   STRACE_IO(("-->OUT"));
00181 
00182         
00183   return &ans_sample;
00184 
00185 }
00186 
00187 void* tsp_exec_feature_1_svc(TSP_exec_feature_t exec_feature, struct svc_req * rqstp)
00188 {
00189         
00190   STRACE_IO(("-->IN"));
00191 
00192   STRACE_IO(("-->OUT"));
00193 
00194   return (void*)NULL;
00195 }
00196 
00197 
00198 static int TSP_rpc_init(TSP_rpc_request_config_t *config)
00199 {
00200   int rpcport = -1;
00201 
00202   STRACE_IO(("-->IN"));
00203 
00204 #ifdef VXWORKS
00205   if(rpcTaskInit() == ERROR)
00206     {
00207       config->server_number = -1;
00208       STRACE_IO(("-->OUT "));
00209       return config->server_number;
00210     }
00211 #endif
00212 
00213   /* look for a free port */
00214   while(rpcport && config->server_number<TSP_MAX_SERVER_NUMBER)
00215     {
00216       rpcport = getrpcport("localhost", TSP_get_progid(config->server_number), TSP_RPC_VERSION_INITIAL, IPPROTO_TCP);
00217       if(rpcport)
00218         config->server_number++;
00219     }
00220 
00221   if(rpcport && config->server_number >= TSP_MAX_SERVER_NUMBER)
00222       config->server_number = -1;
00223 
00224   STRACE_IO(("-->OUT "));
00225 
00226   return config->server_number;
00227 }
00228 
00229 static void TSP_rpc_run(TSP_rpc_request_config_t *config)
00230 {
00231   int32_t rpc_progid = TSP_get_progid(config->server_number);
00232 
00233   /* svc_create does not exist for linux, we must use the deprecated function */
00234   //pmap_unset (rpc_progid, TSP_RPC_VERSION_INITIAL);
00235         
00236   config->xprt = svctcp_create(RPC_ANYSOCK, 0, 0);
00237   if (config->xprt == NULL) 
00238     {
00239       STRACE_ERROR(("Cannot create TCP service"));
00240       return;
00241     }
00242 
00243   if (!svc_register(config->xprt, rpc_progid, TSP_RPC_VERSION_INITIAL, tsp_rpc_1, IPPROTO_TCP))
00244     {
00245       STRACE_ERROR(("RPC server unable to register ProgId=%X",  rpc_progid));
00246       return;
00247     }
00248 
00249   STRACE_DEBUG(("RPC server is being be started with ProgId=%X", rpc_progid));
00250   
00251   STRACE_DEBUG(("launching svc_run..."));
00252   svc_run();
00253   STRACE_INFO(("svc_run returned"));
00254 
00255 }
00256 
00257 static void TSP_rpc_stop(TSP_rpc_request_config_t *config)
00258 {
00259   //STRACE_DEBUG(("calling svc_exit..."));
00260   //svc_destroy(config->xprt);
00261 
00262   /* Clean-up Port map so that next provider could use this ProgId */
00263   if(config->server_number >= 0)
00264     {
00265       svc_unregister(TSP_get_progid(config->server_number),TSP_RPC_VERSION_INITIAL);
00266       pmap_unset (TSP_get_progid(config->server_number), TSP_RPC_VERSION_INITIAL);
00267     }
00268 }
00269 
00270 /*==================================================================*/
00271 
00272 int TSP_rpc_request(TSP_provider_request_handler_t* this)
00273 {
00274   this->config             = TSP_rpc_request_config;
00275   this->run                = TSP_rpc_request_run;
00276   this->stop               = TSP_rpc_request_stop;
00277   this->url                = TSP_rpc_request_url;
00278   this->tid                = (pthread_t)-1;
00279 
00280   this->config_param       = calloc(1, sizeof(TSP_rpc_request_config_t));
00281 
00282   this->status             = TSP_RQH_STATUS_IDLE;
00283   return TRUE;
00284 }
00285 
00286 int TSP_rpc_request_config(TSP_provider_request_handler_t* this)
00287 {
00288   TSP_rpc_request_config_t *config = (TSP_rpc_request_config_t *)(this->config_param);
00289   char hostname[MAXHOSTNAMELEN], *servername;
00290 
00291   config->server_number = TSP_provider_get_server_base_number();
00292   /* do not buffer overflow */
00293   memset(&config->url[0],'\0',TSP_URL_MAXLENGTH);
00294   
00295   config->server_number = TSP_rpc_init(config);
00296   if(config->server_number < 0)
00297     {
00298       STRACE_ERROR(("unable to register any RPC progid :\n\tcheck RPC daemons, or use tsp_rpc_cleanup to clean-up all TSP RPC port mapping"));
00299       this->status = TSP_RQH_STATUS_IDLE;
00300 
00301       return FALSE;
00302     }
00303   else
00304     {
00305       gethostname(hostname, MAXHOSTNAMELEN);
00306       servername = GLU_get_server_name();
00307       
00308       sprintf(config->url, /* TSP_URL_MAXLENGTH, pour snprintf quand Solaris 2.5 sera mort */
00309                TSP_URL_FORMAT, TSP_RPC_PROTOCOL, hostname, servername, config->server_number);
00310 
00311       this->status = TSP_RQH_STATUS_CONFIGURED;
00312 
00313       return TRUE;
00314     }
00315 
00316 } /* end of TSP_rpc_request_config */
00317 
00318 
00319 
00320 void* TSP_rpc_request_run(TSP_provider_request_handler_t* this)
00321 {
00322 
00323   TSP_rpc_request_config_t *config = (TSP_rpc_request_config_t *)(this->config_param);
00324 
00325   STRACE_IO(("-->IN"));  
00326  
00327   //pthread_detach(pthread_self()); /* FIXME shoudl we do this */
00328 
00329   if(config->server_number >= 0)
00330     {
00331       this->status = TSP_RQH_STATUS_RUNNING;
00332       TSP_rpc_run(config);
00333       this->status = TSP_RQH_STATUS_IDLE;
00334    }
00335 
00336   STRACE_IO(("-->OUT"));
00337 
00338   return (void*)NULL;
00339 } /* end of TSP_rpc_request_run */
00340 
00341 char *TSP_rpc_request_url(TSP_provider_request_handler_t* this)
00342 {
00343   TSP_rpc_request_config_t *config = (TSP_rpc_request_config_t*)(this->config_param);
00344   if(this->status == TSP_RQH_STATUS_RUNNING)
00345     return config->url;
00346   else
00347     return NULL;
00348 }
00349 
00350 int TSP_rpc_request_stop(TSP_provider_request_handler_t* this)
00351 {
00352   TSP_rpc_request_config_t *config = (TSP_rpc_request_config_t*)(this->config_param);
00353   
00354   TSP_rpc_stop(config);
00355   this->status = TSP_RQH_STATUS_STOPPED;
00356 
00357   return TRUE;
00358 } /* end of TSP_rpc_request_stop */
00359 
00360 
00361 #else
00362 int main(void)
00363 {
00364   int servernumber;
00365   for(servernumber=0; servernumber<TSP_MAX_SERVER_NUMBER; servernumber++)
00366     {
00367       svc_unregister (TSP_get_progid(servernumber), TSP_RPC_VERSION_INITIAL);
00368       pmap_unset (TSP_get_progid(servernumber), TSP_RPC_VERSION_INITIAL);
00369     }
00370   return 0;
00371 }
00372 #endif /* TSP_RPC_CLEANUP */
Framework Home Page.

Beware !! TSP wave is coming...