File: actionreply.h

package info (click to toggle)
tntnet 3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,488 kB
  • sloc: cpp: 16,636; javascript: 8,109; ansic: 2,189; makefile: 861; sh: 317; xml: 258; perl: 159; sql: 14
file content (58 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download
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
#ifndef ACTIONREPLY_H
#define ACTIONREPLY_H

#include "noty.h"

// Represents a reply for a action.
// A action is a http request, which do not expect any output other than
// success or failure or notifications.
// The class is derived from Noty, which adds methods for noty.js notifications.
// On the server side those notifications are displayed when the action request
// is sent back.
//
class ActionReply : public Noty
{
    friend void operator <<= (cxxtools::SerializationInfo& si, const ActionReply& reply);

public:
    ActionReply()
        : _success(true)
        { }

    void setSuccess(const cxxtools::String& m = cxxtools::String())
    {
        _success = true;
        if (!m.empty())
            success(m);
    }

    void setSuccess(const std::string& m)
    {
        _success = true;
        success(m);
    }

    void setFailed(const cxxtools::String& m)
    {
        _success = false;
        error(m);
    }

    void setFailed(const std::string& m)
    {
        _success = false;
        error(m);
    }

private:
    bool _success;
};

inline void operator <<= (cxxtools::SerializationInfo& si, const ActionReply& reply)
{
    si.addMember("success") <<= reply._success;
    si.addMember("notifications") <<= static_cast<const Noty&>(reply);
}

#endif // ACTIONREPLY_H