sandboxed-api/oss-internship-2020/guetzli/guetzli_transaction.h

60 lines
1.8 KiB
C
Raw Normal View History

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>
#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"
namespace guetzli::sandbox {
2020-08-12 06:44:13 +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:
explicit GuetzliTransaction(TransactionParams params, int retry_count = 0)
: sapi::Transaction(std::make_unique<GuetzliSapiSandbox>()),
params_(std::move(params)) {
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-08-12 06:48:48 +08:00
sapi::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
};
} // namespace guetzli::sandbox
2020-08-13 05:09:40 +08:00
#endif // GUETZLI_SANDBOXED_GUETZLI_TRANSACTION_H_