summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tvsetting/CBlobDeviceFile.cpp (plain)
blob: cd6f10a9ab5436e03c5b5862bb738bf992299c56
1#include <stdio.h>
2#include <unistd.h>
3#include <string.h>
4#include <sys/stat.h>
5#include <fcntl.h>
6#include <errno.h>
7#include "tvconfig/tvconfig.h"
8#include "CBlobDeviceFile.h"
9#include "CTvLog.h"
10
11
12
13#define LOG_TAG "BLOB_FILE"
14
15CBlobDeviceFile::CBlobDeviceFile()
16{
17 m_dev_total_size = 4 * 1024;
18 m_dev_fd = -1;
19 mDataBuf = new unsigned char[m_dev_total_size];
20
21 const char *device_path = config_get_str(CFG_SECTION_SETTING, "device_path", "/param/default_data");
22 const char *device_size = config_get_str(CFG_SECTION_SETTING, "device_size", "0x1000");
23 strcpy(m_dev_path, device_path);
24}
25
26CBlobDeviceFile::~CBlobDeviceFile()
27{
28 if (mDataBuf != NULL) {
29 delete mDataBuf;
30 mDataBuf = NULL;
31 }
32 CloseDevice();
33}
34
35int CBlobDeviceFile::WriteBytes(int offset, int size, unsigned char *buf)
36{
37
38 lseek(m_dev_fd, offset, SEEK_SET);
39 write(m_dev_fd, buf, size);
40 //not need
41 //fsync(device_fd);
42 return 0;
43}
44int CBlobDeviceFile::ReadBytes(int offset, int size, unsigned char *buf)
45{
46 lseek(m_dev_fd, offset, SEEK_SET);
47 read(m_dev_fd, buf, size);
48 return 0;
49}
50int CBlobDeviceFile::EraseAllData()
51{
52 return 0;
53}
54int CBlobDeviceFile::InitCheck()
55{
56 return 0;
57}
58
59int CBlobDeviceFile::OpenDevice()
60{
61 if (strlen(m_dev_path) <= 0) return -1;
62
63 m_dev_fd = open(m_dev_path, O_RDWR | O_SYNC | O_CREAT, S_IRUSR | S_IWUSR);
64
65 if (m_dev_fd < 0) {
66 LOGE("%s, Open device file \"%s\" error: %s.\n", "TV", m_dev_path, strerror(errno));
67 return -1;
68 }
69
70 return 0;
71}
72
73int CBlobDeviceFile::CloseDevice()
74{
75 if (m_dev_fd >= 0) {
76 close(m_dev_fd);
77 m_dev_fd = -1;
78 }
79 return 0;
80}
81