Notification ActionUpdateClient::toDo() { pid_t child_pid; child_pid = fork(); if (child_pid < 0) { cout << getpid() << " > Fork failed!!" << endl; abort(); } if (child_pid == 0) { cout << getpid() << " > Me voy a actualizar!!" << endl; /* * Esperamos 5 segundos simulando un trabajo */ sleep(10); cout << getpid() << " > Termino la actualizacion, creo una conneccion y envio el resultado" << endl; ConnectionSSL connection; connection.setClient(this->connection->getClient()); connection.createEncryptedSocket(); Notification persistent_sender; persistent_sender.setAction(ACTION_PERSISTENT_SENDER); persistent_sender.addDataItem(JSONNode("Token", ACCESS_TOKEN)); OutcomingActionExecutor outcoming_executor(&connection); outcoming_executor.writeAndWaitResponse(persistent_sender); /* * Envio los resultados obtenidos */ Notification response; response.setAction(ACTION_NOTIFICATION_RESPONSE); response.setParentId(this->notification.getId()); response.clearData(); response.addDataItem(JSONNode("UpdateStatus", "OK")); outcoming_executor.writeAndWaitResponse(response); /* * Cierro la coneccion */ connection.informClosingToServer(); connection.manageCloseConnection(0); } Notification response; response.setAction(ACTION_NOTIFICATION_RESPONSE); response.setParentId(this->notification.getId()); response.clearData(); response.addDataItem(JSONNode("UpdateStatus", "INICIADO")); return response; }
int main(int argc, char** argv) { pid_t rc_pid; pid_t child_pid; int chld_state; struct sigaction sigact_close_client; sigemptyset(&sigact_close_client.sa_mask); sigact_close_client.sa_flags = 0; sigact_close_client.sa_handler = manageCloseClient; sigaction(SIGTERM, &sigact_close_client, NULL); sigaction(SIGABRT, &sigact_close_client, NULL); sigaction(SIGKILL, &sigact_close_client, NULL); sigaction(SIGINT, &sigact_close_client, NULL); child_pid = fork(); if (child_pid < 0) { cout << getpid() << " > Fork failed!!" << endl; abort(); } if (child_pid == 0) { cout << getpid() << " > Inciando proceso hijo PERSISTENT_RECEIVER!!" << endl; connection.setClient(&client); connection.createEncryptedSocket(); OutcomingActionExecutor outcoming_executor(&connection); Notification notification; notification.setAction("PERSISTENT_RECEIVER"); notification.addDataItem(JSONNode("Token", ACCESS_TOKEN)); outcoming_executor.writeAndWaitResponse(notification); exit(0); } else { cout << getpid() << " > I'm your father " << child_pid << "!!" << endl; } /* * Esperamos a que los procesos hijos terminen */ rc_pid = wait(&chld_state); cout << getpid() << " > Rc Pid: " << rc_pid << endl; return 0; }