]> rtime.felk.cvut.cz Git - frescor/fwp.git/blobdiff - fwp/lib/core/fwp_vres.c
adding negt functions
[frescor/fwp.git] / fwp / lib / core / fwp_vres.c
index 8d1c721283afa19fc7588e78dd61891ddf798fa8..380ca60d2fa538e3dbcaadc541ca60a85956b1fa 100644 (file)
@@ -120,7 +120,14 @@ int fwp_vres_table_init(unsigned int nr_vres)
        return 0;
 }
 
-static fwp_vres_t* fwp_vres_alloc()
+fwp_vres_id_t fwp_vres_get_id(fwp_vres_d_t vresd)
+{
+       fwp_vres_t *vres = vresd;
+       
+       return (fwp_vres_table.entry - vres);
+}
+
+fwp_vres_d_t fwp_vres_alloc()
 {
        int i;
        unsigned int nr_vres;
@@ -148,6 +155,45 @@ static inline void fwp_vres_free(fwp_vres_t *vres)
        vres->status = FWP_VRES_FREE;
 }
 
+int fwp_vres_set_params(fwp_vres_params_t *params, fwp_vres_d_t vresd)
+{
+       fwp_vres_t *vres = vresd;
+       int rv;
+       
+       /* copy vres paramters into vres structure */
+       memcpy(&vres->params, params, sizeof(struct fwp_vres_params));
+       if (vres->status != FWP_VRES_INACTIVE) {
+               /* Consider: hwo to change parameters when vres is in running
+                * state - restart thread, set vres_resched flag
+                */
+               pthread_cancel(vres->tx_thread);
+               close(vres->ac_sockd);
+               /* or set vres_resched flag and return */
+       } else{
+               /* initialize msg queue */
+               fwp_msgq_init(&vres->tx_queue);
+       }
+       /* open ac socket */
+       if ((rv = fwp_vres_ac_open(vres->params.ac_id)) < 0) {
+               goto err;
+       }
+       vres->ac_sockd = rv;    
+
+       pthread_attr_init(&vres->tx_thread_attr);
+       if ((rv = pthread_create(&vres->tx_thread, &vres->tx_thread_attr, 
+                           fwp_vres_tx_thread, (void*) vres)) != 0){
+               goto err;
+
+       }
+       vres->status = FWP_VRES_UNBOUND;
+       
+/*     return vres->params.id; */
+       return 0;
+err:   
+       fwp_vres_free(vres);
+       return rv; 
+}
+
 int fwp_vres_create(fwp_vres_params_t *params, fwp_vres_d_t *vresdp)
 {
        int rv;