CPPMyth
Library to interoperate with MythTV server
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 
26 using namespace Myth;
27 
28 WSStream::WSStream()
29 : m_response(NULL)
30 , m_position(0)
31 {
32 }
33 
34 WSStream::WSStream(WSResponse *response)
35 : m_response(response)
36 , m_position(0)
37 {
38 }
39 
40 WSStream::~WSStream()
41 {
42  SAFE_DELETE(m_response);
43 }
44 
45 int WSStream::Read(void* buffer, unsigned n)
46 {
47  if (m_response == NULL)
48  return 0;
49  size_t s = m_response->ReadContent((char *)buffer, n);
50  m_position += s;
51  return (int)s;
52 }
53 
54 int64_t WSStream::GetSize() const
55 {
56  return (m_response != NULL ? (int64_t)(-1) : 0);
57 }
58 
59 int64_t WSStream::GetPosition() const
60 {
61  return (m_response != NULL ? m_position : 0);
62 }
63 
64 int64_t WSStream::Seek(int64_t offset, WHENCE_t whence)
65 {
66  (void)offset;
67  (void)whence;
68  return GetPosition();
69 }
70 
71 std::string WSStream::GetContentType() const
72 {
73  std::string val;
74  if (m_response->GetHeaderValue("CONTENT-TYPE", val))
75  return val.substr(0, val.find(';'));
76  return val;
77 }
This is the main namespace that encloses all public classes.
Definition: mythcontrol.h:29