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
|
class CommitCallbacks {
private:
PatchMessageReportReceiver _messageReceiver;
PatchScriptReportReceiver _scriptReceiver;
RemoveResolvableReportReceiver _removeReceiver;
InstallResolvableReportReceiver _installReceiver;
Target_Type _instance;
public:
CommitCallbacks()
: _instance(Target_Null)
{
_messageReceiver.connect();
_scriptReceiver.connect();
_installReceiver.connect();
_removeReceiver.connect();
// printf("CommitCallbacks @ %p\n", this);
}
~CommitCallbacks()
{
// printf("~CommitCallbacks @ %p\n", this);
_removeReceiver.disconnect();
_installReceiver.disconnect();
_scriptReceiver.disconnect();
_messageReceiver.disconnect();
disconnect();
}
/*
* Connect callback to receiver instance
* Pass NULL receiver to disconnect
*
*/
void connect(Target_Type instance) {
// fprintf(stderr, "connect(%p)\n", instance);
disconnect();
if (instance) {
_instance = instance;
Target_INCREF(_instance);
_messageReceiver.instance = _instance;
_scriptReceiver.instance = _instance;
_installReceiver.instance = _instance;
_removeReceiver.instance = _instance;
}
}
/*
* Disconnect receiver instance
*
*/
void disconnect() {
// fprintf(stderr, "disconnect(%p)\n", _instance);
if (_instance != Target_Null) {
_messageReceiver.instance = Target_Null;
_scriptReceiver.instance = Target_Null;
_installReceiver.instance = Target_Null;
_removeReceiver.instance = Target_Null;
Target_DECREF(_instance);
_instance = Target_Null;
}
}
/*
* Get current receiver instance
*
*/
Target_Type receiver() {
// fprintf(stderr, "receiver(%p)\n", _instance);
return _instance;
}
};
/*
* A (dummy) commit callback emitter used for testing only
*
*/
class CommitCallbacksEmitter {
private:
callback::SendReport<target::rpm::InstallResolvableReport> _install_resolvable;
callback::SendReport<target::rpm::RemoveResolvableReport> _remove_resolvable;
callback::SendReport<target::PatchMessageReport> _patch_message;
callback::SendReport<target::PatchScriptReport> _patch_script;
public:
/*
* InstallResolvableReport
*
*/
void install_start(zypp::ResObject::constPtr resobj)
{
_install_resolvable->start( resobj );
}
bool install_progress(zypp::ResObject::constPtr resobj, int value)
{
return _install_resolvable->progress( value, resobj ); /* arguments reversed :-/ */
}
target::rpm::InstallResolvableReport::Action install_problem(
zypp::ResObject::constPtr resobj,
target::rpm::InstallResolvableReport::Error error,
const std::string & description,
target::rpm::InstallResolvableReport::RpmLevel level)
{
return _install_resolvable->problem( resobj, error, description, level );
}
void install_finish(
zypp::ResObject::constPtr resobj,
target::rpm::InstallResolvableReport::Error error,
const std::string & reason,
target::rpm::InstallResolvableReport::RpmLevel level)
{
return _install_resolvable->finish( resobj, error, reason, level );
}
/*
* RemoveResolvableReport
*
*/
void remove_start(zypp::ResObject::constPtr resobj)
{
_remove_resolvable->start( resobj );
}
bool remove_progress(zypp::ResObject::constPtr resobj, int value)
{
return _remove_resolvable->progress( value, resobj ); /* arguments reversed :-/ */
}
target::rpm::RemoveResolvableReport::Action remove_problem(
zypp::ResObject::constPtr resobj,
target::rpm::RemoveResolvableReport::Error error,
const std::string & description)
{
return _remove_resolvable->problem( resobj, error, description );
}
void remove_finish(
zypp::ResObject::constPtr resobj,
target::rpm::RemoveResolvableReport::Error error,
const std::string & reason)
{
return _remove_resolvable->finish( resobj, error, reason );
}
/*
* PatchMessageReport
*
*/
bool patch_message(zypp::Patch::constPtr & patch)
{
return _patch_message->show(patch);
}
/*
* PatchScriptReport
*
*/
void script_start( const zypp::Package::constPtr & package,
const zypp::Pathname & path_r ) // script path
{
_patch_script->start(package, path_r);
}
/**
* Progress provides the script output. If the script is quiet,
* from time to time still-alive pings are sent to the ui. (Notify=PING)
* Returning \c FALSE aborts script execution.
*/
bool script_progress( target::PatchScriptReport::Notify kind, const std::string &output )
{
return _patch_script->progress(kind, output);
}
/** Report error. */
target::PatchScriptReport::Action script_problem( const std::string & description )
{
return _patch_script->problem(description);
}
/** Report success. */
void finish()
{
_patch_script->finish();
}
};
#define REMOVE_NO_ERROR target::rpm::RemoveResolvableReport::NO_ERROR
#define INSTALL_NO_ERROR target::rpm::InstallResolvableReport::NO_ERROR
|