Changeset - 693424e9b9c2
[Not reviewed]
0 4 0
Jan Kaluza - 13 years ago 2012-07-17 13:22:49
hanzz.k@gmail.com
Another part of SettingsAdHocCommand
4 files changed with 49 insertions and 3 deletions:
0 comments (0 inline, 0 general)
include/transport/adhoccommand.h
Show inline comments
 
@@ -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.
include/transport/settingsadhoccommand.h
Show inline comments
 
@@ -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 {
src/adhoccommand.cpp
Show inline comments
 
@@ -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);
 
}
 

	
 
}
src/settingsadhoccommand.cpp
Show inline comments
 
@@ -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::handleRequest(boost::shared_ptr<Swift::Command> payload) {
 
	boost::shared_ptr<Swift::Command> response;
 
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;
 
}
0 comments (0 inline, 0 general)