1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <map>
#include <memory>
#include <string>
#include <boost/signals2.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/Elements/Command.h>
#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/JID/JID.h>
namespace Swift {
class IQRouter;
class SWIFTEN_API OutgoingAdHocCommandSession {
public:
/**
* Availability of action.
*/
enum ActionState {
Absent /** Action isn't applicable to this command. */ = 0,
Present /** Action is applicable to this command */= 1,
Enabled /** Action is applicable and currently available */ = 2,
EnabledAndPresent = 3};
OutgoingAdHocCommandSession(const JID& to, const std::string& commandNode, IQRouter* iqRouter);
~OutgoingAdHocCommandSession();
/**
* Send initial request to the target.
*/
void start();
/**
* Cancel command session with the target.
*/
void cancel();
/**
* Return to the previous stage.
*/
void goBack();
/**
* Send the form to complete the command.
* \param form Form for submission - if missing the command will be submitted with no form.
*/
void complete(Form::ref form);
/**
* Send the form to advance to the next stage of the command.
* \param form Form for submission - if missing the command will be submitted with no form.
*/
void goNext(Form::ref form);
/**
* Is the form multi-stage?
*/
bool getIsMultiStage() const;
/**
* Emitted when the form for the next stage is available.
*/
boost::signals2::signal<void (Command::ref)> onNextStageReceived;
/**
* Emitted on error.
*/
boost::signals2::signal<void (ErrorPayload::ref)> onError;
/**
* Get the state of a given action.
* This is useful for a UI to determine which buttons should be visible,
* and which enabled.
* Use for Next, Prev, Cancel and Complete only.
* If no actions are available, the command has completed.
*/
ActionState getActionState(Command::Action action) const;
private:
void handleResponse(std::shared_ptr<Command> payload, ErrorPayload::ref error);
void submitForm(Form::ref, Command::Action action);
private:
JID to_;
std::string commandNode_;
IQRouter* iqRouter_;
bool isMultiStage_;
std::string sessionID_;
std::map<Command::Action, ActionState> actionStates_;
boost::signals2::connection connection_;
};
}
|