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 PresenceOnServer is_on_server()
const {
return is_on_server_; }
54 CurrentOp operation()
const {
return current_operation_; }
55 bool children_ready() {
return children_.empty(); }
56 void LaunchNotify() { is_on_server_ = PresenceOnServer::kObjectInProgress; }
57 std::chrono::steady_clock::time_point RequestStartTime()
const {
return request_start_time_; }
58 ServerResponse LastOperationResult()
const {
return last_operation_result_; }
61 using childiter = std::list<OSTreeObject::ptr>::iterator;
62 typedef std::pair<OSTreeObject*, childiter> parentref;
65 void AddParent(
OSTreeObject* parent, std::list<OSTreeObject::ptr>::iterator parent_it);
68 void ChildNotify(std::list<OSTreeObject::ptr>::iterator child_it);
72 void AppendChild(
const OSTreeObject::ptr& child);
75 void PopulateChildren();
81 std::string Url()
const;
85 void CheckChildren(
RequestPool& pool,
long rescode);
88 void PresenceError(
RequestPool& pool, int64_t rescode);
91 void UploadError(
RequestPool& pool, int64_t rescode);
93 static size_t curl_handle_write(
void* buffer,
size_t size,
size_t nmemb,
void* userp);
95 FRIEND_TEST(OstreeObject, Request);
96 FRIEND_TEST(OstreeObject, UploadDryRun);
97 FRIEND_TEST(OstreeObject, UploadFail);
98 FRIEND_TEST(OstreeObject, UploadSuccess);
101 friend std::ostream& operator<<(std::ostream& stream,
const OSTreeObject& o);
103 const boost::filesystem::path file_path_;
104 const std::string object_name_;
108 PresenceOnServer is_on_server_;
109 CurrentOp current_operation_{};
111 std::stringstream http_response_;
114 std::list<parentref> parents_;
115 std::list<OSTreeObject::ptr> children_;
117 std::chrono::steady_clock::time_point request_start_time_;
118 ServerResponse last_operation_result_{ServerResponse::kNoResponse};
122 OSTreeObject::ptr ostree_object_from_curl(CURL* curlhandle);
124 std::ostream& operator<<(std::ostream& stream,
const OSTreeObject::ptr& o);
127 #endif // SOTA_CLIENT_TOOLS_OSTREE_OBJECT_H_