Shaka Packager SDK
Loading...
Searching...
No Matches
callback_file.cc
1// Copyright 2017 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#include <packager/file/callback_file.h>
8
9#include <cstdint>
10
11#include <absl/log/log.h>
12
13#include <packager/file.h>
14#include <packager/macros/compiler.h>
15
16namespace shaka {
17
18CallbackFile::CallbackFile(const char* file_name, const char* mode)
19 : File(file_name), file_mode_(mode) {}
20
21CallbackFile::~CallbackFile() {}
22
23bool CallbackFile::Close() {
24 delete this;
25 return true;
26}
27
28int64_t CallbackFile::Read(void* buffer, uint64_t length) {
29 if (!callback_params_->read_func) {
30 LOG(ERROR) << "Read function not defined.";
31 return -1;
32 }
33 return callback_params_->read_func(name_, buffer, length);
34}
35
36int64_t CallbackFile::Write(const void* buffer, uint64_t length) {
37 if (!callback_params_->write_func) {
38 LOG(ERROR) << "Write function not defined.";
39 return -1;
40 }
41 return callback_params_->write_func(name_, buffer, length);
42}
43
44void CallbackFile::CloseForWriting() {}
45
46int64_t CallbackFile::Size() {
47 LOG(INFO) << "CallbackFile does not support Size().";
48 return -1;
49}
50
51bool CallbackFile::Flush() {
52 // Do nothing on Flush.
53 return true;
54}
55
56bool CallbackFile::Seek(uint64_t position) {
57 UNUSED(position);
58 VLOG(1) << "CallbackFile does not support Seek().";
59 return false;
60}
61
62bool CallbackFile::Tell(uint64_t* position) {
63 UNUSED(position);
64 VLOG(1) << "CallbackFile does not support Tell().";
65 return false;
66}
67
68bool CallbackFile::Open() {
69 if (file_mode_ != "r" && file_mode_ != "w" && file_mode_ != "rb" &&
70 file_mode_ != "wb") {
71 LOG(ERROR) << "CallbackFile does not support file mode " << file_mode_;
72 return false;
73 }
74 return ParseCallbackFileName(file_name(), &callback_params_, &name_);
75}
76
77} // namespace shaka
CallbackFile(const char *file_name, const char *mode)
All the methods that are virtual are virtual for mocking.