xref: /haiku/headers/os/package/CommitTransactionResult.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2014, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _PACKAGE__COMMIT_TRANSACTION_RESULT_H_
6 #define _PACKAGE__COMMIT_TRANSACTION_RESULT_H_
7 
8 
9 #include <ObjectList.h>
10 #include <String.h>
11 
12 
13 class BMessage;
14 
15 
16 namespace BPackageKit {
17 
18 
19 enum BTransactionError {
20 	B_TRANSACTION_OK = 0,
21 	B_TRANSACTION_NO_MEMORY,
22 	B_TRANSACTION_INTERNAL_ERROR,
23 	B_TRANSACTION_INSTALLATION_LOCATION_BUSY,
24 	B_TRANSACTION_CHANGE_COUNT_MISMATCH,
25 	B_TRANSACTION_BAD_REQUEST,
26 	B_TRANSACTION_NO_SUCH_PACKAGE,
27 	B_TRANSACTION_PACKAGE_ALREADY_EXISTS,
28 	B_TRANSACTION_FAILED_TO_GET_ENTRY_PATH,
29 	B_TRANSACTION_FAILED_TO_OPEN_DIRECTORY,
30 	B_TRANSACTION_FAILED_TO_CREATE_DIRECTORY,
31 	B_TRANSACTION_FAILED_TO_REMOVE_DIRECTORY,
32 	B_TRANSACTION_FAILED_TO_MOVE_DIRECTORY,
33 	B_TRANSACTION_FAILED_TO_WRITE_ACTIVATION_FILE,
34 	B_TRANSACTION_FAILED_TO_READ_PACKAGE_FILE,
35 	B_TRANSACTION_FAILED_TO_EXTRACT_PACKAGE_FILE,
36 	B_TRANSACTION_FAILED_TO_OPEN_FILE,
37 	B_TRANSACTION_FAILED_TO_MOVE_FILE,
38 	B_TRANSACTION_FAILED_TO_COPY_FILE,
39 	B_TRANSACTION_FAILED_TO_WRITE_FILE_ATTRIBUTE,
40 	B_TRANSACTION_FAILED_TO_ACCESS_ENTRY,
41 	B_TRANSACTION_FAILED_TO_ADD_GROUP,
42 	B_TRANSACTION_FAILED_TO_ADD_USER,
43 	B_TRANSACTION_FAILED_TO_ADD_USER_TO_GROUP,
44 	B_TRANSACTION_FAILED_TO_CHANGE_PACKAGE_ACTIVATION,
45 };
46 
47 
48 class BTransactionIssue {
49 public:
50 			enum BType {
51 				B_WRITABLE_FILE_TYPE_MISMATCH,
52 				B_WRITABLE_FILE_NO_PACKAGE_ATTRIBUTE,
53 				B_WRITABLE_FILE_OLD_ORIGINAL_FILE_MISSING,
54 				B_WRITABLE_FILE_OLD_ORIGINAL_FILE_TYPE_MISMATCH,
55 				B_WRITABLE_FILE_COMPARISON_FAILED,
56 				B_WRITABLE_FILE_NOT_EQUAL,
57 				B_WRITABLE_SYMLINK_COMPARISON_FAILED,
58 				B_WRITABLE_SYMLINK_NOT_EQUAL,
59 				B_POST_INSTALL_SCRIPT_NOT_FOUND,
60 				B_STARTING_POST_INSTALL_SCRIPT_FAILED,
61 				B_POST_INSTALL_SCRIPT_FAILED,
62 				B_PRE_UNINSTALL_SCRIPT_NOT_FOUND,
63 				B_STARTING_PRE_UNINSTALL_SCRIPT_FAILED,
64 				B_PRE_UNINSTALL_SCRIPT_FAILED,
65 			};
66 
67 public:
68 								BTransactionIssue();
69 								BTransactionIssue(BType type,
70 									const BString& packageName,
71 									const BString& path1, const BString& path2,
72  									status_t systemError, int exitCode);
73 								BTransactionIssue(
74 									const BTransactionIssue& other);
75 								~BTransactionIssue();
76 
77 			BType				Type() const;
78 			const BString&		PackageName() const;
79 			const BString&		Path1() const;
80 			const BString&		Path2() const;
81 			status_t			SystemError() const;
82 			int					ExitCode() const;
83 
84 			BString				ToString() const;
85 
86 			status_t			AddToMessage(BMessage& message) const;
87 			status_t			ExtractFromMessage(const BMessage& message);
88 
89 			BTransactionIssue&	operator=(const BTransactionIssue& other);
90 
91 private:
92 			BType				fType;
93 			BString				fPackageName;
94 			BString				fPath1;
95 			BString				fPath2;
96  			status_t			fSystemError;
97 			int					fExitCode;
98 };
99 
100 
101 class BCommitTransactionResult {
102 public:
103 								BCommitTransactionResult();
104 								BCommitTransactionResult(
105 									BTransactionError error);
106 								BCommitTransactionResult(
107 									const BCommitTransactionResult& other);
108 								~BCommitTransactionResult();
109 
110 			void				Unset();
111 
112 			int32				CountIssues() const;
113 			const BTransactionIssue* IssueAt(int32 index) const;
114 			bool				AddIssue(const BTransactionIssue& issue);
115 
116 			BTransactionError	Error() const;
117 			void				SetError(BTransactionError error);
118 
119 			status_t			SystemError() const;
120 			void				SetSystemError(status_t error);
121 
122 			const BString&		ErrorPackage() const;
123 									// may be empty, even on error
124 			void				SetErrorPackage(const BString& packageName);
125 
126 			BString				FullErrorMessage() const;
127 
128 			const BString&		Path1() const;
129 			void				SetPath1(const BString& path);
130 
131 			const BString&		Path2() const;
132 			void				SetPath2(const BString& path);
133 
134 			const BString&		Path3() const;
135 			void				SetPath3(const BString& path);
136 
137 			const BString&		String1() const;
138 			void				SetString1(const BString& string);
139 
140 			const BString&		String2() const;
141 			void				SetString2(const BString& string);
142 
143 			const BString&		OldStateDirectory() const;
144 			void				SetOldStateDirectory(const BString& directory);
145 
146 			status_t			AddToMessage(BMessage& message) const;
147 			status_t			ExtractFromMessage(const BMessage& message);
148 
149 			BCommitTransactionResult& operator=(
150 									const BCommitTransactionResult& other);
151 
152 private:
153 			typedef BObjectList<BTransactionIssue> IssueList;
154 
155 private:
156 			BTransactionError	fError;
157 			status_t			fSystemError;
158 			BString				fErrorPackage;
159 			BString				fPath1;
160 			BString				fPath2;
161 			BString				fString1;
162 			BString				fString2;
163 			BString				fOldStateDirectory;
164 			IssueList			fIssues;
165 };
166 
167 
168 }	// namespace BPackageKit
169 
170 
171 #endif	// _PACKAGE__COMMIT_TRANSACTION_RESULT_H_
172