1 #ifndef SOTA_CLIENT_TOOLS_OSTREE_OBJECT_H_
2 #define SOTA_CLIENT_TOOLS_OSTREE_OBJECT_H_
9 #include <boost/filesystem.hpp>
10 #include <boost/intrusive_ptr.hpp>
11 #include "gtest/gtest_prod.h"
14 #include "treehub_server.h"
19 enum class PresenceOnServer { kObjectStateUnknown, kObjectPresent, kObjectMissing, kObjectInProgress };
21 enum class CurrentOp { kOstreeObjectUploading, kOstreeObjectPresenceCheck };
28 enum class ServerResponse { kNoResponse, kOk, kTemporaryFailure };
32 using ptr = boost::intrusive_ptr<OSTreeObject>;
45 void MakeTestRequest(
const TreehubServer& push_target, CURLM* curl_multi_handle);
51 void CurlDone(CURLM* curl_multi_handle,
RequestPool& pool);
53 uintmax_t GetSize() {
return boost::filesystem::file_size(file_path_); }
55 PresenceOnServer is_on_server()
const {
return is_on_server_; }
56 CurrentOp operation()
const {
return current_operation_; }
57 bool children_ready() {
return children_.empty(); }
58 void LaunchNotify() { is_on_server_ = PresenceOnServer::kObjectInProgress; }
59 std::chrono::steady_clock::time_point RequestStartTime()
const {
return request_start_time_; }
60 ServerResponse LastOperationResult()
const {
return last_operation_result_; }
63 using childiter = std::list<OSTreeObject::ptr>::iterator;
64 typedef std::pair<OSTreeObject*, childiter> parentref;
67 void AddParent(
OSTreeObject* parent, std::list<OSTreeObject::ptr>::iterator parent_it);
70 void ChildNotify(std::list<OSTreeObject::ptr>::iterator child_it);
74 void AppendChild(
const OSTreeObject::ptr& child);
77 void PopulateChildren();
83 std::string Url()
const;
87 void CheckChildren(
RequestPool& pool,
long rescode);
90 void PresenceError(
RequestPool& pool, int64_t rescode);
93 void UploadError(
RequestPool& pool, int64_t rescode);
95 static size_t curl_handle_write(
void* buffer,
size_t size,
size_t nmemb,
void* userp);
97 FRIEND_TEST(OstreeObject, Request);
98 FRIEND_TEST(OstreeObject, UploadDryRun);
99 FRIEND_TEST(OstreeObject, UploadFail);
100 FRIEND_TEST(OstreeObject, UploadSuccess);
103 friend std::ostream& operator<<(std::ostream& stream,
const OSTreeObject& o);
105 const boost::filesystem::path file_path_;
106 const std::string object_name_;
110 PresenceOnServer is_on_server_;
111 CurrentOp current_operation_{};
113 std::stringstream http_response_;
116 std::list<parentref> parents_;
117 std::list<OSTreeObject::ptr> children_;
119 std::chrono::steady_clock::time_point request_start_time_;
120 ServerResponse last_operation_result_{ServerResponse::kNoResponse};
124 OSTreeObject::ptr ostree_object_from_curl(CURL* curlhandle);
126 std::ostream& operator<<(std::ostream& stream,
const OSTreeObject::ptr& o);
129 #endif // SOTA_CLIENT_TOOLS_OSTREE_OBJECT_H_