-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcompressor.h
93 lines (67 loc) · 2.96 KB
/
compressor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPRESSOR_H_
#define COMPRESSOR_H_
#include <ctime>
#include <pthread.h>
#include "archive.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/var_array_buffer.h"
#include "ppapi/cpp/var_dictionary.h"
#include "ppapi/utility/completion_callback_factory.h"
#include "ppapi/utility/threading/simple_thread.h"
#include "compressor_archive.h"
#include "compressor_stream.h"
#include "javascript_compressor_requestor_interface.h"
#include "javascript_message_sender_interface.h"
// Handles all packing operations like creating archive objects and writing data
// onto the archive.
class Compressor {
public:
Compressor(const pp::InstanceHandle& instance_handle /* Used for workers. */,
int compressor_id,
JavaScriptMessageSenderInterface* message_sender);
virtual ~Compressor();
// Initializes the compressor.
bool Init();
// Creates an archive object.
void CreateArchive();
// Adds an entry to the archive.
void AddToArchive(const pp::VarDictionary& dictionary);
// Processes a file chunk sent from JavaScript.
void ReadFileChunkDone(const pp::VarDictionary& dictionary);
// Receives a write chunk response from JavaScript.
void WriteChunkDone(const pp::VarDictionary& dictionary);
// Releases all resources obtained by libarchive.
void CloseArchive(const pp::VarDictionary& dictionary);
// A getter function for the message sender.
JavaScriptMessageSenderInterface* message_sender() { return message_sender_; }
// A getter function for the requestor.
JavaScriptCompressorRequestorInterface* requestor() { return requestor_; }
// A getter function for the compressor id.
int compressor_id() { return compressor_id_; }
private:
// A callback helper for AddToArchive.
void AddToArchiveCallback(int32_t, const pp::VarDictionary& dictionary);
// A callback helper for CloseArchive.
void CloseArchiveCallback(int32_t, bool has_error);
// The compressor id of this compressor.
int compressor_id_;
// An object that sends messages to JavaScript.
JavaScriptMessageSenderInterface* message_sender_;
// A worker for jobs that require blocking operations or a lot of processing
// time. Those shouldn't be done on the main thread. The jobs submitted to
// this thread are executed in order, so a new job must wait for the last job
// to finish.
pp::SimpleThread worker_;
// Callback factory used to submit jobs to worker_.
pp::CompletionCallbackFactory<Compressor> callback_factory_;
// A requestor for making calls to JavaScript.
JavaScriptCompressorRequestorInterface* requestor_;
// Libarchive wrapper instance per compressor, shared across all operations.
CompressorArchive* compressor_archive_;
// An instance that takes care of all IO operations.
CompressorStream* compressor_stream_;
};
#endif /// COMPRESSOR_H_