Open Lighting Architecture: plugins/spi/FakeSPIWriter.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
FakeSPIWriter.h
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * FakeSPIWriter.h
17 * The SPIWriter used for testing.
18 * Copyright (C) 2013 Simon Newton
19 */
20
21#ifndef PLUGINS_SPI_FAKESPIWRITER_H_
22#define PLUGINS_SPI_FAKESPIWRITER_H_
23
24#include <ola/testing/TestUtils.h>
25#include <ola/thread/Mutex.h>
26#include <stdint.h>
27#include <string>
28#include "plugins/spi/SPIWriter.h"
29
30namespace ola {
31namespace plugin {
32namespace spi {
33
37 class FakeSPIWriter : public SPIWriterInterface {
38 public:
39 explicit FakeSPIWriter(const std::string &device_path)
40 : m_device_path(device_path),
41 m_write_pending(0),
42 m_writes(0),
43 m_last_write_size(0),
44 m_data(NULL) {
45 }
46
47 ~FakeSPIWriter() {
48 delete[] m_data;
49 }
50
51 bool Init() { return true; }
52
53 std::string DevicePath() const { return m_device_path; }
54
55 bool WriteSPIData(const uint8_t *data, unsigned int length);
56
57 // Methods used for testing
58 void BlockWriter();
59 void UnblockWriter();
60
61 void ResetWrite();
62 void WaitForWrite();
63
64 unsigned int WriteCount() const;
65 unsigned int LastWriteSize() const;
66 void CheckDataMatches(const ola::testing::SourceLine &source_line,
67 const uint8_t *data,
68 unsigned int length);
69
70 private:
71 const std::string m_device_path;
72 bool m_write_pending; // GUARDED_BY(m_mutex)
73 unsigned int m_writes; // GUARDED_BY(m_mutex)
74 unsigned int m_last_write_size; // GUARDED_BY(m_mutex)
75 uint8_t *m_data; // GUARDED_BY(m_mutex)
76
77 ola::thread::Mutex m_write_lock;
78 mutable ola::thread::Mutex m_mutex;
79 ola::thread::ConditionVariable m_cond_var;
80};
81
82} // namespace spi
83} // namespace plugin
84} // namespace ola
85#endif // PLUGINS_SPI_FAKESPIWRITER_H_
ola::plugin::spi::SPIWriterInterface
Definition SPIWriter.h:36
ola::thread::ConditionVariable
Definition Mutex.h:83
ola::thread::Mutex
Definition Mutex.h:41
ola::plugin::spi
Code for SPI devices.
ola::plugin
Code for supported devices and protocols.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44