Commit 1717f6fb authored by legoc's avatar legoc
Browse files

(split) Added getExitCode() in Instance, the server sends the status with the exit code

parent 77a8a9f2
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* Removed Configuration::getRetries(). * Removed Configuration::getRetries().
* Added storage functions: This::storeKeyValue(), This::getKeyValue(), This::removeKey(), Instance::getKeyValue(). * Added storage functions: This::storeKeyValue(), This::getKeyValue(), This::removeKey(), Instance::getKeyValue().
* Added Instance::getPastStates(). * Added Instance::getPastStates().
* Added Instance.getExitCode().
0.3.3 0.3.3
----- -----
......
...@@ -234,6 +234,11 @@ public: ...@@ -234,6 +234,11 @@ public:
*/ */
std::set<State> getPastStates() const; std::set<State> getPastStates() const;
/**
* Returns the exit code.
*/
int getExitCode() const;
bool getBinaryResult(std::string& result); bool getBinaryResult(std::string& result);
bool getResult(std::string& result); bool getResult(std::string& result);
...@@ -260,6 +265,7 @@ private: ...@@ -260,6 +265,7 @@ private:
State m_lastState; State m_lastState;
bool m_hasResult; bool m_hasResult;
std::string m_resultData; std::string m_resultData;
int m_exitCode;
std::unique_ptr<WaitingImpl> m_waiting; std::unique_ptr<WaitingImpl> m_waiting;
}; };
......
...@@ -439,7 +439,8 @@ Instance::Instance(Server * server) : ...@@ -439,7 +439,8 @@ Instance::Instance(Server * server) :
m_pastStates(0), m_pastStates(0),
m_initialState(UNKNOWN), m_initialState(UNKNOWN),
m_lastState(UNKNOWN), m_lastState(UNKNOWN),
m_hasResult(false) { m_hasResult(false),
m_exitCode(-1) {
m_waiting.reset(new GenericWaitingImpl(bind(&Instance::cancelWaitFor, this))); m_waiting.reset(new GenericWaitingImpl(bind(&Instance::cancelWaitFor, this)));
} }
...@@ -572,6 +573,11 @@ State Instance::waitFor(int states, const std::string& eventName, StateHandlerTy ...@@ -572,6 +573,11 @@ State Instance::waitFor(int states, const std::string& eventName, StateHandlerTy
m_pastStates = status->getPastStates(); m_pastStates = status->getPastStates();
m_lastState = state; m_lastState = state;
// Assign the exit code.
if (status->getExitCode() != -1) {
m_exitCode = status->getExitCode();
}
// Call the state handler. // Call the state handler.
if (handler != nullptr) { if (handler != nullptr) {
handler(state); handler(state);
...@@ -651,6 +657,10 @@ std::set<State> Instance::getPastStates() const { ...@@ -651,6 +657,10 @@ std::set<State> Instance::getPastStates() const {
return m_server->getPastStates(m_id); return m_server->getPastStates(m_id);
} }
int Instance::getExitCode() const {
return m_exitCode;
}
bool Instance::getBinaryResult(std::string& result) { bool Instance::getBinaryResult(std::string& result) {
waitFor(); waitFor();
......
...@@ -59,6 +59,9 @@ std::unique_ptr<Event> EventStreamSocket::receive(bool blocking) { ...@@ -59,6 +59,9 @@ std::unique_ptr<Event> EventStreamSocket::receive(bool blocking) {
application::State state = event[message::StatusEvent::APPLICATION_STATE].GetInt(); application::State state = event[message::StatusEvent::APPLICATION_STATE].GetInt();
application::State pastStates = event[message::StatusEvent::PAST_APPLICATION_STATES].GetInt(); application::State pastStates = event[message::StatusEvent::PAST_APPLICATION_STATES].GetInt();
if (event.HasMember(message::StatusEvent::EXIT_CODE)) {
return unique_ptr<Event>(new StatusEvent(id, name, state, pastStates, event[message::StatusEvent::EXIT_CODE].GetInt()));
}
return unique_ptr<Event>(new StatusEvent(id, name, state, pastStates)); return unique_ptr<Event>(new StatusEvent(id, name, state, pastStates));
} }
else if (response == message::Event::RESULT) { else if (response == message::Event::RESULT) {
......
...@@ -20,14 +20,18 @@ ...@@ -20,14 +20,18 @@
namespace cameo { namespace cameo {
StatusEvent::StatusEvent(int id, const std::string& name, application::State state, application::State pastStates) : StatusEvent::StatusEvent(int id, const std::string& name, application::State state, application::State pastStates, int exitCode) :
Event(id, name), Event(id, name),
m_state(state), m_state(state),
m_pastStates(pastStates) { m_pastStates(pastStates),
m_exitCode(exitCode) {
} }
StatusEvent::StatusEvent(const StatusEvent& event) : StatusEvent::StatusEvent(const StatusEvent& event) :
Event(event), m_state(event.m_state), m_pastStates(event.m_pastStates) { Event(event),
m_state(event.m_state),
m_pastStates(event.m_pastStates),
m_exitCode(event.m_exitCode) {
} }
StatusEvent* StatusEvent::clone() { StatusEvent* StatusEvent::clone() {
...@@ -42,6 +46,10 @@ application::State StatusEvent::getPastStates() const { ...@@ -42,6 +46,10 @@ application::State StatusEvent::getPastStates() const {
return m_pastStates; return m_pastStates;
} }
int StatusEvent::getExitCode() const {
return m_exitCode;
}
std::ostream& operator<<(std::ostream& os, const cameo::StatusEvent& status) { std::ostream& operator<<(std::ostream& os, const cameo::StatusEvent& status) {
os << "name=" << status.m_name os << "name=" << status.m_name
<< "\nid=" << status.m_id << "\nid=" << status.m_id
......
...@@ -28,17 +28,19 @@ class StatusEvent : public Event { ...@@ -28,17 +28,19 @@ class StatusEvent : public Event {
friend std::ostream& operator<<(std::ostream&, const StatusEvent&); friend std::ostream& operator<<(std::ostream&, const StatusEvent&);
public: public:
StatusEvent(int id, const std::string& name, application::State state, application::State pastStates); StatusEvent(int id, const std::string& name, application::State state, application::State pastStates, int exitCode = -1);
StatusEvent(const StatusEvent& event); StatusEvent(const StatusEvent& event);
virtual StatusEvent* clone(); virtual StatusEvent* clone();
application::State getState() const; application::State getState() const;
application::State getPastStates() const; application::State getPastStates() const;
int getExitCode() const;
private: private:
application::State m_state; application::State m_state;
application::State m_pastStates; application::State m_pastStates;
int m_exitCode; // TODO replace with optional
}; };
std::ostream& operator<<(std::ostream&, const StatusEvent&); std::ostream& operator<<(std::ostream&, const StatusEvent&);
......
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