CPPMyth
Library to interoperate with MythTV server
Loading...
Searching...
No Matches
mythwsstream.cpp
1/*
2 * Copyright (C) 2014 Jean-Luc Barriere
3 *
4 * This Program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This Program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 */
21
22#include "mythwsstream.h"
23#include "private/wsresponse.h"
24#include "private/cppdef.h"
25
26using namespace Myth;
27
28WSStream::WSStream()
29: m_response(nullptr)
30, m_position(0)
31{
32}
33
34WSStream::WSStream(WSResponse *response)
35: m_response(response)
36, m_position(0)
37{
38}
39
40WSStream::~WSStream()
41{
42 SAFE_DELETE(m_response);
43}
44
45int WSStream::Read(void* buffer, unsigned n)
46{
47 if (m_response == nullptr)
48 return 0;
49 int s = m_response->ReadContent((char *)buffer, n);
50 if (s < 0)
51 return (-1);
52 m_position += s;
53 return s;
54}
55
56int64_t WSStream::GetSize() const
57{
58 return (m_response != nullptr ? (int64_t)(-1) : 0);
59}
60
61int64_t WSStream::GetPosition() const
62{
63 return (m_response != nullptr ? m_position : 0);
64}
65
66int64_t WSStream::Seek(int64_t offset, WHENCE_t whence)
67{
68 (void)offset;
69 (void)whence;
70 return GetPosition();
71}
72
73std::string WSStream::GetContentType() const
74{
75 const std::string& val = m_response->GetHeaderValue("CONTENT-TYPE");
76 return val.substr(0, val.find(';'));
77}
This is the main namespace that encloses all public classes.
Definition mythcontrol.h:30