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 <absl/log/log.h>
10
11#include <packager/macros/compiler.h>
12#include <packager/macros/logging.h>
13
14namespace shaka {
15
16CallbackFile::CallbackFile(const char* file_name, const char* mode)
17 : File(file_name), file_mode_(mode) {}
18
19CallbackFile::~CallbackFile() {}
20
21bool CallbackFile::Close() {
22 delete this;
23 return true;
24}
25
26int64_t CallbackFile::Read(void* buffer, uint64_t length) {
27 if (!callback_params_->read_func) {
28 LOG(ERROR) << "Read function not defined.";
29 return -1;
30 }
31 return callback_params_->read_func(name_, buffer, length);
32}
33
34int64_t CallbackFile::Write(const void* buffer, uint64_t length) {
35 if (!callback_params_->write_func) {
36 LOG(ERROR) << "Write function not defined.";
37 return -1;
38 }
39 return callback_params_->write_func(name_, buffer, length);
40}
41
42void CallbackFile::CloseForWriting() {}
43
44int64_t CallbackFile::Size() {
45 LOG(INFO) << "CallbackFile does not support Size().";
46 return -1;
47}
48
49bool CallbackFile::Flush() {
50 // Do nothing on Flush.
51 return true;
52}
53
54bool CallbackFile::Seek(uint64_t position) {
55 UNUSED(position);
56 VLOG(1) << "CallbackFile does not support Seek().";
57 return false;
58}
59
60bool CallbackFile::Tell(uint64_t* position) {
61 UNUSED(position);
62 VLOG(1) << "CallbackFile does not support Tell().";
63 return false;
64}
65
66bool CallbackFile::Open() {
67 if (file_mode_ != "r" && file_mode_ != "w" && file_mode_ != "rb" &&
68 file_mode_ != "wb") {
69 LOG(ERROR) << "CallbackFile does not support file mode " << file_mode_;
70 return false;
71 }
72 return ParseCallbackFileName(file_name(), &callback_params_, &name_);
73}
74
75} // namespace shaka
CallbackFile(const char *file_name, const char *mode)
All the methods that are virtual are virtual for mocking.