Shaka Packager SDK
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 
14 namespace shaka {
15 
16 CallbackFile::CallbackFile(const char* file_name, const char* mode)
17  : File(file_name), file_mode_(mode) {}
18 
19 CallbackFile::~CallbackFile() {}
20 
21 bool CallbackFile::Close() {
22  delete this;
23  return true;
24 }
25 
26 int64_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 
34 int64_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 
42 void CallbackFile::CloseForWriting() {}
43 
44 int64_t CallbackFile::Size() {
45  LOG(INFO) << "CallbackFile does not support Size().";
46  return -1;
47 }
48 
49 bool CallbackFile::Flush() {
50  // Do nothing on Flush.
51  return true;
52 }
53 
54 bool CallbackFile::Seek(uint64_t position) {
55  UNUSED(position);
56  VLOG(1) << "CallbackFile does not support Seek().";
57  return false;
58 }
59 
60 bool CallbackFile::Tell(uint64_t* position) {
61  UNUSED(position);
62  VLOG(1) << "CallbackFile does not support Tell().";
63  return false;
64 }
65 
66 bool 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.
Definition: crypto_flags.cc:66