2020-08-13 05:09:40 +08:00
|
|
|
// Copyright 2020 Google LLC
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef GUETZLI_SANDBOXED_GUETZLI_TRANSACTION_H_
|
|
|
|
#define GUETZLI_SANDBOXED_GUETZLI_TRANSACTION_H_
|
2020-08-12 06:44:13 +08:00
|
|
|
|
|
|
|
#include <syscall.h>
|
|
|
|
|
2020-09-17 23:36:07 +08:00
|
|
|
#include "guetzli_sandbox.h" // NOLINT(build/include)
|
2020-08-12 06:44:13 +08:00
|
|
|
#include "sandboxed_api/transaction.h"
|
|
|
|
#include "sandboxed_api/vars.h"
|
|
|
|
|
2020-08-31 17:19:00 +08:00
|
|
|
namespace guetzli::sandbox {
|
2020-08-12 06:44:13 +08:00
|
|
|
|
2020-09-17 23:36:07 +08:00
|
|
|
enum class ImageType { kJpeg, kPng };
|
2020-08-12 06:44:13 +08:00
|
|
|
|
|
|
|
struct TransactionParams {
|
2020-08-18 04:29:07 +08:00
|
|
|
const char* in_file = nullptr;
|
|
|
|
const char* out_file = nullptr;
|
2020-08-12 06:48:48 +08:00
|
|
|
int verbose = 0;
|
|
|
|
int quality = 0;
|
|
|
|
int memlimit_mb = 0;
|
2020-08-12 06:44:13 +08:00
|
|
|
};
|
|
|
|
|
2020-08-12 06:48:48 +08:00
|
|
|
// Instance of this transaction shouldn't be reused
|
|
|
|
// Create a new one for each processing operation
|
2020-08-12 06:44:13 +08:00
|
|
|
class GuetzliTransaction : public sapi::Transaction {
|
|
|
|
public:
|
2020-08-31 17:19:00 +08:00
|
|
|
explicit GuetzliTransaction(TransactionParams params, int retry_count = 0)
|
|
|
|
: sapi::Transaction(std::make_unique<GuetzliSapiSandbox>()),
|
2020-09-17 23:36:07 +08:00
|
|
|
params_(std::move(params)) {
|
2020-08-31 17:19:00 +08:00
|
|
|
set_retry_count(retry_count);
|
|
|
|
SetTimeLimit(absl::InfiniteDuration());
|
2020-08-12 06:44:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
absl::Status Main() final;
|
|
|
|
|
2020-08-18 04:29:07 +08:00
|
|
|
absl::Status LinkOutFile(int out_fd) const;
|
2020-09-25 22:43:06 +08:00
|
|
|
absl::StatusOr<ImageType> GetImageTypeFromFd(int fd) const;
|
2020-08-12 06:44:13 +08:00
|
|
|
|
|
|
|
const TransactionParams params_;
|
2020-08-13 05:09:40 +08:00
|
|
|
ImageType image_type_ = ImageType::kJpeg;
|
2020-08-12 06:44:13 +08:00
|
|
|
};
|
|
|
|
|
2020-08-31 17:19:00 +08:00
|
|
|
} // namespace guetzli::sandbox
|
2020-08-13 05:09:40 +08:00
|
|
|
|
|
|
|
#endif // GUETZLI_SANDBOXED_GUETZLI_TRANSACTION_H_
|