Commit a0d2d4ce authored by Millian Poquet's avatar Millian Poquet

[code] sonarQ smell: code duplication

parent 52578e94
......@@ -212,12 +212,12 @@ IPMessage::~IPMessage()
} break;
case IPMessageType::SWITCHED_ON:
{
SwitchONMessage * msg = (SwitchONMessage *) data;
SwitchMessage * msg = (SwitchMessage *) data;
delete msg;
} break;
case IPMessageType::SWITCHED_OFF:
{
SwitchOFFMessage * msg = (SwitchOFFMessage *) data;
SwitchMessage * msg = (SwitchMessage *) data;
delete msg;
} break;
case IPMessageType::WAITING_DONE:
......
......@@ -200,23 +200,14 @@ struct SchedWaitAnswerMessage
};
/**
* @brief The content of the SwitchON message
* @brief The content of the SwitchON/SwitchOFF message
*/
struct SwitchONMessage
struct SwitchMessage
{
int machine_id; //!< The unique number of the machine which should be switched ON
int new_pstate; //!< The power state the machine should be put into
};
/**
* @brief The content of the SwitchOFF message
*/
struct SwitchOFFMessage
{
int machine_id; //!< The unique number of the machine which should be switched OFF
int new_pstate; //!< The power state the machine should be put into
};
/**
* @brief The content of the KillingDone message
*/
......
......@@ -61,7 +61,7 @@ int switch_on_machine_process(int argc, char *argv[])
machine->update_machine_state(MachineState::IDLE);
SwitchONMessage * msg = new SwitchONMessage;
SwitchMessage * msg = new SwitchMessage;
msg->machine_id = args->machine_id;
msg->new_pstate = args->new_pstate;
send_message("server", IPMessageType::SWITCHED_ON, (void *) msg);
......@@ -116,7 +116,7 @@ int switch_off_machine_process(int argc, char *argv[])
machine->update_machine_state(MachineState::SLEEPING);
SwitchOFFMessage * msg = new SwitchOFFMessage;
SwitchMessage * msg = new SwitchMessage;
msg->machine_id = args->machine_id;
msg->new_pstate = args->new_pstate;
send_message("server", IPMessageType::SWITCHED_OFF, (void *) msg);
......
......@@ -63,8 +63,8 @@ int server_process(int argc, char *argv[])
handler_map[IPMessageType::KILLING_DONE] = server_on_killing_done;
handler_map[IPMessageType::SUBMITTER_HELLO] = server_on_submitter_hello;
handler_map[IPMessageType::SUBMITTER_BYE] = server_on_submitter_bye;
handler_map[IPMessageType::SWITCHED_ON] = server_on_switched_on;
handler_map[IPMessageType::SWITCHED_OFF] = server_on_switched_off;
handler_map[IPMessageType::SWITCHED_ON] = server_on_switched;
handler_map[IPMessageType::SWITCHED_OFF] = server_on_switched;
handler_map[IPMessageType::END_DYNAMIC_SUBMIT] = server_on_end_dynamic_submit;
// Simulation loop
......@@ -401,37 +401,11 @@ void server_on_wait_query(ServerData * data,
//origin_of_wait_queries[{message->nb_resources,message->processing_time}] = submitter;
}
void server_on_switched_on(ServerData * data,
IPMessage * task_data)
{
xbt_assert(task_data->data != nullptr);
SwitchONMessage * message = (SwitchONMessage *) task_data->data;
xbt_assert(data->context->machines.exists(message->machine_id));
Machine * machine = data->context->machines[message->machine_id];
(void) machine; // Avoids a warning if assertions are ignored
xbt_assert(MSG_host_get_pstate(machine->host) == message->new_pstate);
MachineRange all_switched_machines;
if (data->context->current_switches.mark_switch_as_done(message->machine_id, message->new_pstate,
all_switched_machines, data->context))
{
if (data->context->trace_machine_states)
data->context->machine_state_tracer.write_machine_states(MSG_get_clock());
data->context->proto_writer->append_resource_state_changed(all_switched_machines,
std::to_string(message->new_pstate),
MSG_get_clock());
}
--data->nb_switching_machines;
}
void server_on_switched_off(ServerData * data,
IPMessage * task_data)
void server_on_switched(ServerData * data,
IPMessage * task_data)
{
xbt_assert(task_data->data != nullptr);
SwitchOFFMessage * message = (SwitchOFFMessage *) task_data->data;
SwitchMessage * message = (SwitchMessage *) task_data->data;
xbt_assert(data->context->machines.exists(message->machine_id));
Machine * machine = data->context->machines[message->machine_id];
......
......@@ -142,21 +142,13 @@ void server_on_wait_query(ServerData * data,
IPMessage * task_data);
/**
* @brief Server SWITCHED_ON handler
* @brief Server SWITCHED_ON/SWITCHED_OFF handler
* @param[in,out] data The data associated with the server_process
* @param[in,out] task_data The data associated with the message the server received
*/
void server_on_switched_on(ServerData * data,
void server_on_switched(ServerData * data,
IPMessage * task_data);
/**
* @brief Server SWITCHED_OFF handler
* @param[in,out] data The data associated with the server_process
* @param[in,out] task_data The data associated with the message the server received
*/
void server_on_switched_off(ServerData * data,
IPMessage * task_data);
/**
* @brief Server KILLING_DONE handler
* @param[in,out] data The data associated with the server_process
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment