xref: /haiku/headers/os/package/CommitTransactionResult.h (revision 850f2d1e58cc443f77353c7fc0ce0c158c1fd328)
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 			};
63 
64 public:
65 								BTransactionIssue();
66 								BTransactionIssue(BType type,
67 									const BString& packageName,
68 									const BString& path1, const BString& path2,
69  									status_t systemError, int exitCode);
70 								BTransactionIssue(
71 									const BTransactionIssue& other);
72 								~BTransactionIssue();
73 
74 			BType				Type() const;
75 			const BString&		PackageName() const;
76 			const BString&		Path1() const;
77 			const BString&		Path2() const;
78 			status_t			SystemError() const;
79 			int					ExitCode() const;
80 
81 			BString				ToString() const;
82 
83 			status_t			AddToMessage(BMessage& message) const;
84 			status_t			ExtractFromMessage(const BMessage& message);
85 
86 			BTransactionIssue&	operator=(const BTransactionIssue& other);
87 
88 private:
89 			BType				fType;
90 			BString				fPackageName;
91 			BString				fPath1;
92 			BString				fPath2;
93  			status_t			fSystemError;
94 			int					fExitCode;
95 };
96 
97 
98 class BCommitTransactionResult {
99 public:
100 								BCommitTransactionResult();
101 								BCommitTransactionResult(
102 									BTransactionError error);
103 								BCommitTransactionResult(
104 									const BCommitTransactionResult& other);
105 								~BCommitTransactionResult();
106 
107 			void				Unset();
108 
109 			int32				CountIssues() const;
110 			const BTransactionIssue* IssueAt(int32 index) const;
111 			bool				AddIssue(const BTransactionIssue& issue);
112 
113 			BTransactionError	Error() const;
114 			void				SetError(BTransactionError error);
115 
116 			status_t			SystemError() const;
117 			void				SetSystemError(status_t error);
118 
119 			const BString&		ErrorPackage() const;
120 									// may be empty, even on error
121 			void				SetErrorPackage(const BString& packageName);
122 
123 			BString				FullErrorMessage() const;
124 
125 			const BString&		Path1() const;
126 			void				SetPath1(const BString& path);
127 
128 			const BString&		Path2() const;
129 			void				SetPath2(const BString& path);
130 
131 			const BString&		Path3() const;
132 			void				SetPath3(const BString& path);
133 
134 			const BString&		String1() const;
135 			void				SetString1(const BString& string);
136 
137 			const BString&		String2() const;
138 			void				SetString2(const BString& string);
139 
140 			const BString&		OldStateDirectory() const;
141 			void				SetOldStateDirectory(const BString& directory);
142 
143 			status_t			AddToMessage(BMessage& message) const;
144 			status_t			ExtractFromMessage(const BMessage& message);
145 
146 			BCommitTransactionResult& operator=(
147 									const BCommitTransactionResult& other);
148 
149 private:
150 			typedef BObjectList<BTransactionIssue> IssueList;
151 
152 private:
153 			BTransactionError	fError;
154 			status_t			fSystemError;
155 			BString				fErrorPackage;
156 			BString				fPath1;
157 			BString				fPath2;
158 			BString				fString1;
159 			BString				fString2;
160 			BString				fOldStateDirectory;
161 			IssueList			fIssues;
162 };
163 
164 
165 }	// namespace BPackageKit
166 
167 
168 #endif	// _PACKAGE__COMMIT_TRANSACTION_RESULT_H_
169