Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 909 → Rev 930

/shark/trunk/ports/first/server-task.c
34,7 → 34,7
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: server-task.c,v 1.14 2004-12-17 13:19:42 trimarchi Exp $
* CVS : $Id: server-task.c,v 1.15 2005-01-18 15:04:52 trimarchi Exp $
*/
 
#include "ll/i386/64bit.h"
50,11 → 50,13
//#define FSF_DEBUG
extern fsf_server_id_t service_server;
 
typedef enum {WAIT_SIGNAL, WAIT_RENEGOTIATION, ACTIVE} service_task_status;
 
TASK service_task(void) {
struct mess msg;
fsf_renegotiation_status_t status;
int wait_renegotiation=0;
service_task_status stask_status=ACTIVE;
 
PORT rec,tra;
63,106 → 65,123
tra = port_connect("CHANR",sizeof(struct mess),STREAM,WRITE);
while(1) {
// wait for operation
if (wait_renegotiation) {
if (!fsf_get_renegotiation_status(msg.server,&status)) {
if (status==FSF_ADMITTED) {
// send response server is -1 if the operation fail
 
switch(stask_status) {
// wait for operation
case WAIT_RENEGOTIATION:
if (!fsf_get_renegotiation_status(msg.server,&status)) {
if (status==FSF_ADMITTED) {
// send response server is -1 if the operation fail
#ifdef FSF_DEBUG
kern_printf("ADM");
kern_printf("ADM");
#endif
wait_renegotiation=0;
//kern_printf("(REN %d)", msg.server);
port_send(tra,&msg,BLOCK);
stask_status=ACTIVE;
//kern_printf("(REN %d)", msg.server);
port_send(tra,&msg,BLOCK);
 
continue;
} else
continue;
} else
#ifdef FSF_DEBUG
kern_printf("WAIT")
kern_printf("WAIT")
#endif
;
}
break;
 
case WAIT_SIGNAL:
if (!fsf_get_renegotiation_status(msg.server,&status)) {
if (status==FSF_ADMITTED) {
sigqueue(msg.process, msg.sig_notify, msg.sig_value);
stask_status=ACTIVE;
}
}
} else {
port_receive(rec,&msg,BLOCK);
break;
 
case ACTIVE:
{
port_receive(rec,&msg,BLOCK);
#ifdef FSF_DEBUG
kern_printf("Message ");
kern_printf("Message ");
#endif
switch (msg.type) {
switch (msg.type) {
case NEGOTIATE_CONTRACT:
if (negotiate_contract(&msg.contract, &msg.server)==FSF_ERR_CONTRACT_REJECTED)
msg.server=-1;
else {
wait_renegotiation=1;
//task_endcycle();
continue;
}
break;
 
case REQUEST_RENEGOTIATE_CONTRACT:
if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED)
msg.server=-1;
break;
case RENEGOTIATE_CONTRACT:
if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED)
msg.server=-1;
else {
wait_renegotiation=1;
//task_endcycle();
continue;
}
break;
case CHANGE_PARAMETER:
{
fsf_contract_parameters_t new_contract;
struct timespec period;
struct timespec budget;
int i=0;
// this CASE change the quality and importance
//fsf_initialize_contract(&new_contract);
// find contract
while(i<current_server) {
if (server_list[i].server==msg.server) break;
i++;
case NEGOTIATE_CONTRACT:
if (negotiate_contract(&msg.contract, &msg.server)==FSF_ERR_CONTRACT_REJECTED)
msg.server=-1;
else {
stask_status=WAIT_RENEGOTIATION;
//task_endcycle();
continue;
}
//kern_printf("(RCQI)");
NULL_TIMESPEC(&period);
ADDUSEC2TIMESPEC(server_list[i].Tmax, &period);
NULL_TIMESPEC(&budget);
ADDUSEC2TIMESPEC(server_list[i].Cmin, &budget);
fsf_set_contract_basic_parameters(&new_contract,&budget,&period,FSF_DEFAULT_WORKLOAD);
NULL_TIMESPEC(&period);
ADDUSEC2TIMESPEC(server_list[i].Tmin, &period);
NULL_TIMESPEC(&budget);
ADDUSEC2TIMESPEC(server_list[i].Cmax, &budget);
break;
 
fsf_set_contract_reclamation_parameters(&new_contract, &budget, &period, FSF_DEFAULT_GRANULARITY,NULL,
msg.qi.quality,msg.qi.importance);
case REQUEST_RENEGOTIATE_CONTRACT:
if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED)
msg.server=-1;
else stask_status=WAIT_SIGNAL;
if (server_list[i].d_equals_t == true) {
NULL_TIMESPEC(&new_contract.deadline);
new_contract.d_equals_t = true;
} else {
break;
case RENEGOTIATE_CONTRACT:
if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED)
msg.server=-1;
else {
stask_status=WAIT_RENEGOTIATION;
//task_endcycle();
continue;
}
break;
case CHANGE_PARAMETER:
{
fsf_contract_parameters_t new_contract;
struct timespec period;
struct timespec budget;
int i=0;
// this CASE change the quality and importance
//fsf_initialize_contract(&new_contract);
// find contract
while(i<current_server) {
if (server_list[i].server==msg.server) break;
i++;
}
//kern_printf("(RCQI)");
NULL_TIMESPEC(&period);
ADDUSEC2TIMESPEC(server_list[i].deadline, &period);
ADDUSEC2TIMESPEC(server_list[i].Tmax, &period);
NULL_TIMESPEC(&budget);
ADDUSEC2TIMESPEC(server_list[i].Cmin, &budget);
fsf_set_contract_basic_parameters(&new_contract,&budget,&period,FSF_DEFAULT_WORKLOAD);
NULL_TIMESPEC(&period);
ADDUSEC2TIMESPEC(server_list[i].Tmin, &period);
NULL_TIMESPEC(&budget);
ADDUSEC2TIMESPEC(server_list[i].Cmax, &budget);
fsf_set_contract_reclamation_parameters(&new_contract, &budget, &period, FSF_DEFAULT_GRANULARITY,NULL,
msg.qi.quality,msg.qi.importance);
if (server_list[i].d_equals_t == true) {
NULL_TIMESPEC(&new_contract.deadline);
new_contract.d_equals_t = true;
} else {
NULL_TIMESPEC(&period);
ADDUSEC2TIMESPEC(server_list[i].deadline, &period);
TIMESPEC_ASSIGN(&new_contract.deadline, &period);
new_contract.d_equals_t = false;
}
if (renegotiate_contract(&new_contract, msg.server)==FSF_ERR_CONTRACT_REJECTED)
msg.server=-1;
}
if (renegotiate_contract(&new_contract, msg.server)==FSF_ERR_CONTRACT_REJECTED)
msg.server=-1;
}
break;
default :
break;
}
break;
 
default :
break;
}
port_send(tra,&msg,BLOCK);
}
port_send(tra,&msg,BLOCK);
}
}
}