summaryrefslogtreecommitdiffstats
path: root/lib/CommLayer/DBusServerProxy.h
blob: b55172be11f3ff1e5c8610b71ed60112b4971899 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
    Copyright (C) 2009  Jiri Moskovcak (jmoskovc@redhat.com)
    Copyright (C) 2009  RedHat inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    */
#include <dbus-c++/dbus.h>
#include <dbus-c++/glib-integration.h>
#include "DBusCommon.h"
#include <map>
#include <iostream>
#include <stdlib.h>

class CDBusServer_adaptor
: public DBus::InterfaceAdaptor
{
public:

    CDBusServer_adaptor()
    : DBus::InterfaceAdaptor(CC_DBUS_IFACE)
    {
        register_method(CDBusServer_adaptor, GetCrashInfos, _GetCrashInfos_stub);
        register_method(CDBusServer_adaptor, CreateReport, _CreateReport_stub);
        register_method(CDBusServer_adaptor, Report, _Report_stub);
        register_method(CDBusServer_adaptor, DeleteDebugDump, _DeleteDebugDump_stub);
        register_method(CDBusServer_adaptor, GetJobResult, _GetJobResult_stub);
    }
/* reveal Interface introspection when we stabilize the API */
/*
    DBus::IntrospectedInterface *const introspect() const
    {
        static DBus::IntrospectedArgument GetCrashInfos_args[] =
        {
            //{ "uid", "i", true},
            { "info", "a{ss}", false },
            { 0, 0, 0 }
        };
        static DBus::IntrospectedArgument Crash_args[] =
        {
            { "package", "s", false },
            { 0, 0, 0 }
        };
        static DBus::IntrospectedMethod CDBusServer_adaptor_methods[] =
        {
            { "GetCrashInfos", GetCrashInfos_args },
            { 0, 0 },
            { "GetCrashInfosMap", GetCrashInfos_args },
            { 0, 0 }
        };
        static DBus::IntrospectedMethod CDBusServer_adaptor_signals[] =
        {
            { "Crash", Crash_args },
            { 0, 0 }
        };
        static DBus::IntrospectedProperty CDBusServer_adaptor_properties[] =
        {
            { 0, 0, 0, 0 }
        };
        static DBus::IntrospectedInterface CDBusServer_adaptor_interface =
        {
            "com.redhat.abrt",
            CDBusServer_adaptor_methods,
            CDBusServer_adaptor_signals,
            CDBusServer_adaptor_properties
        };
        return &CDBusServer_adaptor_interface;
    }
*/
public:

    /* properties exposed by this interface, use
     * property() and property(value) to get and set a particular property
     */

public:

    /* methods exported by this interface,
     * you will have to implement them in your ObjectAdaptor
     */
     virtual vector_crash_infos_t GetCrashInfos(const std::string &pDBusSender) = 0;
     virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pDBusSender) = 0;
     virtual uint64_t CreateReport_t(const std::string &pUUID,const std::string &pDBusSender) = 0;
     virtual bool Report(map_crash_report_t pReport, const std::string &pDBusSender) = 0;
     virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender) = 0;
     virtual map_crash_report_t GetJobResult(uint64_t pJobID, const std::string& pDBusSender) = 0;
     

public:
    /* signal emitters for this interface
     */
    /* Notify the clients (UI) about a new crash */
    void Crash(const std::string& arg1)
    {
        ::DBus::SignalMessage sig("Crash");
        ::DBus::MessageIter wi = sig.writer();
        wi << arg1;
        emit_signal(sig);
    }
    /* Notify the clients that creating a report has finished */
    void AnalyzeComplete(map_crash_report_t arg1)
    {
        ::DBus::SignalMessage sig("AnalyzeComplete");
        ::DBus::MessageIter wi = sig.writer();
        wi << arg1;
        emit_signal(sig);
    }
    
    
    void JobDone(uint64_t job_id)
    {
        ::DBus::SignalMessage sig("JobDone");
        ::DBus::MessageIter wi = sig.writer();
        wi << job_id;
        emit_signal(sig);
    }

    void Error(const std::string& arg1)
    {
        ::DBus::SignalMessage sig("Error");
        ::DBus::MessageIter wi = sig.writer();
        wi << arg1;
        emit_signal(sig);
    }
    
    void Update(const std::string pDest, const std::string& pMessage)
    {
        ::DBus::SignalMessage sig("Update");
        ::DBus::MessageIter wi = sig.writer();
        wi << pDest;
        wi << pMessage;
        emit_signal(sig);
    }
    
    void Warning(const std::string& arg1)
    {
        ::DBus::SignalMessage sig("Warning");
        ::DBus::MessageIter wi = sig.writer();
        wi << arg1;
        emit_signal(sig);
    }

private:

    /* unmarshalers (to unpack the DBus message before calling the actual interface method)
     */
    DBus::Message _GetCrashInfos_stub(const DBus::CallMessage &call)
    {
        DBus::MessageIter ri = call.reader();
        //FIXME: @@@REMOVE!!
        vector_crash_infos_t argout1 = GetCrashInfos(call.sender());
        DBus::ReturnMessage reply(call);
        DBus::MessageIter wi = reply.writer();
        wi << argout1;
        return reply;
    }

    DBus::Message _CreateReport_stub(const DBus::CallMessage &call)
    {
        DBus::MessageIter ri = call.reader();

        std::string argin1; ri >> argin1;
        uint64_t argout1 = CreateReport_t(argin1,call.sender());
        if(sizeof (uint64_t) != 8) abort ();
        //map_crash_report_t argout1 = CreateReport(argin1,call.sender());
        DBus::ReturnMessage reply(call);
        DBus::MessageIter wi = reply.writer();
        wi << argout1;
        return reply;
    }

    DBus::Message _Report_stub(const DBus::CallMessage &call)
    {
        DBus::MessageIter ri = call.reader();

        map_crash_report_t argin1; ri >> argin1;
        bool argout1 = Report(argin1, call.sender());
        DBus::ReturnMessage reply(call);
        DBus::MessageIter wi = reply.writer();
        wi << argout1;
        return reply;
    }

    DBus::Message _DeleteDebugDump_stub(const DBus::CallMessage &call)
    {
        DBus::MessageIter ri = call.reader();

        std::string argin1; ri >> argin1;
        bool argout1 = DeleteDebugDump(argin1,call.sender());
        DBus::ReturnMessage reply(call);
        DBus::MessageIter wi = reply.writer();
        wi << argout1;
        return reply;
    }
    
    DBus::Message _GetJobResult_stub(const DBus::CallMessage &call)
    {
        DBus::MessageIter ri = call.reader();
        uint64_t job_id;
        ri >> job_id;
        map_crash_report_t report = GetJobResult(job_id,call.sender());
        DBus::ReturnMessage reply(call);
        DBus::MessageIter wi = reply.writer();
        wi << report;
        return reply;
    }
};