~unity-api-team/storage-framework/devel

« back to all changes in this revision

Viewing changes to include/unity/storage/provider/TempfileUploadJob.h

  • Committer: Tarmac
  • Author(s): Michi Henning
  • Date: 2017-04-06 08:09:37 UTC
  • mfrom: (118.2.14 add-doc)
  • Revision ID: tarmac-20170406080937-97zduhlyym3yzftj
Added tutorial and provider reference documentation.

Approved by unity-api-1-bot, Michi Henning, James Henstridge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
class TempfileUploadJobImpl;
37
37
}
38
38
 
 
39
/**
 
40
\brief Helper class to store the contents of an upload in a temporary file.
 
41
 
 
42
For uploads, a provider implementation must decide whether to upload data to the cloud provider
 
43
immediately (as soon as the data arrives from the client) or whether to buffer the data locally first
 
44
and upload it to the cloud provider once the client successfully finalizes the upload. Uploading
 
45
immediately has the down side that it is more likely to fail. This is an issue particularly
 
46
for mobile devices, where applications may be suspended for extended periods, and where connectivity
 
47
is often lost without warning. Uploads of large files (such as media files) are unlikely
 
48
to ever complete in this case: if the user swipes away from the client application, no more data arrives
 
49
at the provider until the application resumes, by which time the connection to the cloud provider has
 
50
most likely timed out.
 
51
 
 
52
Especially for files that are more than a few kilobytes in size, it is usually necessary to write the data
 
53
to a local file first and to write it to the cloud provider only once all of data has been sent by the client.
 
54
(The provider service does not get suspended and will not exit while an upload is in progress.)
 
55
 
 
56
TempfileUploadJob is a helper class that implements an uploader that writes the data to a temporary file.
 
57
The file is unlinked once the TempfileUploadJob is destroyed. You implementation must provide finish() and
 
58
cancel().
 
59
 
 
60
*/
 
61
 
39
62
class UNITY_STORAGE_EXPORT TempfileUploadJob : public UploadJob
40
63
{
41
64
public:
 
65
    /**
 
66
    \brief Construct a TempfileUploadJob.
 
67
    \param upload_id An identifier for this particular upload. You can use any non-empty string,
 
68
    as long as it is unique among all uploads that are in progress within this provider.
 
69
    The runtime uses the <code>upload_id</code> to distinguish different uploads that may be
 
70
    in progress concurrently.
 
71
    */
42
72
    TempfileUploadJob(std::string const& upload_id);
43
73
    virtual ~TempfileUploadJob();
44
74
 
 
75
    /**
 
76
    \brief Returns the name of the file.
 
77
    \return The full path name of the temporary file.
 
78
    */
45
79
    std::string file_name() const;
46
80
 
47
 
    // This function should be called from your finish()
48
 
    // implementation to read the remaining data from the socket.  If
49
 
    // the client has not closed the socket as expected, LogicError
50
 
    // will be thrown.
 
81
    /**
 
82
    \brief Reads any unread data from the upload socket and writes it to the temporary file.
 
83
 
 
84
    You must call drain() from your UploadJob::finish() method. Its implementation reads any remaining
 
85
    data from the upload socket and writes it to the temporary file. If an error occurs,
 
86
    drain() throws an exception.
 
87
    \throws LogicException The client did not close its end of the socket.
 
88
    */
51
89
    void drain();
52
90
 
53
 
protected:
 
91
private:
54
92
    TempfileUploadJob(internal::TempfileUploadJobImpl *p) UNITY_STORAGE_HIDDEN;
55
93
};
56
94