]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - src/fwp/fwp/mngr/wifi_agent.c
Add error checking to wifi_agent server
[frescor/frsh-forb.git] / src / fwp / fwp / mngr / wifi_agent.c
1 /*
2  *      @brief server side (frm_fwp) functions for communication 
3  *      resource manager - station
4  */
5
6 #include <frm_generic.h>
7 #include <forb.h>
8 #include <error.h>
9 #include <errno.h>
10 #include <getopt.h>
11 #include <fres_sa_scenario.h>
12 #include <stdbool.h>
13 #include <ul_list.h>
14 #include <ul_log.h>
15 #include <ul_logreg.h>
16 #include <fwp_res.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include "wifi_agent_idl.h"
20 #include "fwp_admctrl.h"
21 #include "wifi_agent.h"
22 #include "fcb.h"
23
24 UL_LOG_CUST(ulogd_fwp_wifi_agent_server);
25 ul_log_domain_t ulogd_fwp_wifi_agent_server = {UL_LOGL_MSG, "fwp_wifi_agent_server"};
26 UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(fwp_wifi_agent_server_logreg_domains, ulogd_fwp_wifi_agent_server);
27
28 struct forb_wifi_agent_idl_impl wifi_agent_impl = {
29         .add = wifi_agent_idl_add,
30         .print_state = wifi_agent_idl_print_state,
31 };
32
33 /**
34  *      Print list of stored stations
35  */
36 void wifi_agent_idl_print_state(wifi_agent_idl _obj, CORBA_Environment *ev)
37 {
38         fwp_sta_t *sta2;
39         struct frm_fwp_priv *frm_fwp_state = forb_instance_data(_obj);
40
41         ul_logmsg("Actual_list_of_stations\n");
42         ul_list_for_each(sta_list, &frm_fwp_state->sta_list, sta2){
43                 ul_logmsg("%llu_-_%d\n", sta2->client_mac_addr, sta2->rate);
44         }
45         ul_logmsg("------------\n\n");
46         
47 }
48
49 /**
50  *      Add information about STA (mac_address & bit rate)
51  */
52 CORBA_long wifi_agent_idl_add(wifi_agent_idl _obj, const CORBA_long rate, const CORBA_long_long client_mac_addr, CORBA_Environment *ev)
53 {
54         struct frm_fwp_priv *frm_fwp_state = forb_instance_data(_obj);
55         fwp_sta_t *sta;
56         fwp_sta_t *new_to_add;
57         const frsh_resource_type_t restype = FRSH_RT_NETWORK;
58         const frsh_resource_id_t resid = 1;
59         CORBA_Environment env;
60
61         /*fill the linked list here*/
62         ul_list_for_each(sta_list, &frm_fwp_state->sta_list, sta){
63                 /*client was sending info before*/
64                 if(sta->client_mac_addr == client_mac_addr) {
65                         /*mac address is the same change only rate*/
66                         pthread_mutex_lock( &frm_fwp_state->mutex );
67                         sta->rate = rate;
68                         pthread_mutex_unlock( &frm_fwp_state->mutex );
69                         //TODO: debug
70                         fres_contract_broker_redistribute_spare_capacity(frm_fwp_state->fcb, restype, resid, &env);
71                         if (forb_exception_occurred(&env)) {
72                                 ul_logerr("fres_contract_broker_redistribute_spare_capacity: %s\n", forb_strerror(&env));
73                                 return fres_forbex2err(&env);
74                         }
75                         return 0;
76                 }
77         }
78         new_to_add = (fwp_sta_t*)malloc(sizeof(fwp_sta_t));
79         /*client was not sending info yet*/
80         new_to_add->rate = rate;
81         new_to_add->client_mac_addr = client_mac_addr;
82         pthread_mutex_lock( &frm_fwp_state->mutex );
83         sta_list_ins_tail(&frm_fwp_state->sta_list, new_to_add);
84         pthread_mutex_unlock( &frm_fwp_state->mutex );
85
86         return 0;
87 }
88