Another part of SettingsAdHocCommand
This commit is contained in:
parent
dd9f9c48e1
commit
693424e9b9
4 changed files with 49 additions and 3 deletions
|
@ -41,6 +41,8 @@ class AdHocCommand {
|
|||
|
||||
virtual boost::shared_ptr<Swift::Command> handleRequest(boost::shared_ptr<Swift::Command> payload) = 0;
|
||||
|
||||
void addFormField(Swift::FormField::ref field);
|
||||
|
||||
const std::string &getId() {
|
||||
return m_id;
|
||||
}
|
||||
|
@ -57,9 +59,10 @@ class AdHocCommand {
|
|||
Component *m_component;
|
||||
Swift::JID m_initiator;
|
||||
Swift::JID m_to;
|
||||
std::vector<Swift::FormField::ref> m_fields;
|
||||
std::string m_id;
|
||||
|
||||
private:
|
||||
std::string m_id;
|
||||
// This is used to remove AdHocCommand after long inactivity to prevent memory leaks
|
||||
// caused by users which disconnect before they finish the command.
|
||||
// AdHocManager uses this to garbage collect old AdHocCommands.
|
||||
|
|
|
@ -34,12 +34,19 @@ class Component;
|
|||
|
||||
class SettingsAdHocCommand : public AdHocCommand {
|
||||
public:
|
||||
typedef enum { Init, WaitingForResponse } State;
|
||||
|
||||
SettingsAdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to);
|
||||
|
||||
/// Destructor.
|
||||
virtual ~SettingsAdHocCommand();
|
||||
|
||||
virtual boost::shared_ptr<Swift::Command> handleRequest(boost::shared_ptr<Swift::Command> payload);
|
||||
|
||||
private:
|
||||
boost::shared_ptr<Swift::Command> getForm();
|
||||
boost::shared_ptr<Swift::Command> handleResponse(boost::shared_ptr<Swift::Command> payload);
|
||||
State m_state;
|
||||
};
|
||||
|
||||
class SettingsAdHocCommandFactory : public AdHocCommandFactory {
|
||||
|
|
|
@ -45,4 +45,8 @@ AdHocCommand::AdHocCommand(Component *component, const Swift::JID &initiator, co
|
|||
AdHocCommand::~AdHocCommand() {
|
||||
}
|
||||
|
||||
void AdHocCommand::addFormField(Swift::FormField::ref field) {
|
||||
m_fields.push_back(field);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,15 +31,47 @@ namespace Transport {
|
|||
DEFINE_LOGGER(logger, "SettingsAdHocCommand");
|
||||
|
||||
SettingsAdHocCommand::SettingsAdHocCommand(Component *component, const Swift::JID &initiator, const Swift::JID &to) : AdHocCommand(component, initiator, to) {
|
||||
m_state = Init;
|
||||
}
|
||||
|
||||
SettingsAdHocCommand::~SettingsAdHocCommand() {
|
||||
}
|
||||
|
||||
boost::shared_ptr<Swift::Command> SettingsAdHocCommand::getForm() {
|
||||
boost::shared_ptr<Swift::Command> response(new Swift::Command("settings", m_id, Swift::Command::Executing));
|
||||
boost::shared_ptr<Swift::Form> form(new Swift::Form());
|
||||
|
||||
BOOST_FOREACH(Swift::FormField::ref field, m_fields) {
|
||||
form->addField(field);
|
||||
}
|
||||
|
||||
response->setForm(form);
|
||||
return response;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Swift::Command> SettingsAdHocCommand::handleResponse(boost::shared_ptr<Swift::Command> payload) {
|
||||
|
||||
|
||||
|
||||
boost::shared_ptr<Swift::Command> response;
|
||||
response->setStatus(Swift::Command::Completed);
|
||||
return response;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Swift::Command> SettingsAdHocCommand::handleRequest(boost::shared_ptr<Swift::Command> payload) {
|
||||
boost::shared_ptr<Swift::Command> response;
|
||||
|
||||
|
||||
|
||||
switch (m_state) {
|
||||
case Init:
|
||||
response = getForm();
|
||||
m_state = WaitingForResponse;
|
||||
break;
|
||||
case WaitingForResponse:
|
||||
response = handleResponse(payload);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue