• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * file_handle.h - File handle
3  *
4  *  Copyright (c) 2016-2017 Intel Corporation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Yinhang Liu <yinhangx.liu@intel.com>
19  * Author: Wind Yuan <feng.yuan@intel.com>
20  */
21 
22 #ifndef XCAM_FILE_HANDLE_H
23 #define XCAM_FILE_HANDLE_H
24 
25 #include <xcam_std.h>
26 
27 namespace XCam {
28 
29 class FileHandle {
30 public:
31     FileHandle ();
32     explicit FileHandle (const char *name, const char *option);
33     virtual ~FileHandle ();
34 
is_valid()35     bool is_valid () const {
36         return (_fp ? true : false);
37     }
38     bool end_of_file ();
39     XCamReturn open (const char *name, const char *option);
40     XCamReturn close ();
41     XCamReturn rewind ();
42     XCamReturn get_file_size (size_t &size);
get_file_name()43     const char* get_file_name () const {
44         return _file_name;
45     }
46     XCamReturn read_file (void *buf, const size_t &size);
47     XCamReturn write_file (const void *buf, const size_t &size);
48 
49 private:
50     XCAM_DEAD_COPY (FileHandle);
51 
52 protected:
53     FILE    *_fp;
54 
55 private:
56     char    *_file_name;
57     size_t   _file_size;
58 };
59 
60 }
61 
62 #endif //XCAM_FILE_HANDLE_H