| Directory: | ./ |
|---|---|
| File: | pdserv/src/lib/Signal.cpp |
| Date: | 2025-11-02 04:09:49 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 23 | 23 | 100.0% |
| Branches: | 2 | 4 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * Copyright 2010 Richard Hacker (lerichi at gmx dot net) | ||
| 4 | * | ||
| 5 | * This file is part of the pdserv library. | ||
| 6 | * | ||
| 7 | * The pdserv library is free software: you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU Lesser General Public License as published | ||
| 9 | * by the Free Software Foundation, either version 3 of the License, or (at | ||
| 10 | * your option) any later version. | ||
| 11 | * | ||
| 12 | * The pdserv library is distributed in the hope that it will be useful, but | ||
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | ||
| 15 | * License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public License | ||
| 18 | * along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | ****************************************************************************/ | ||
| 21 | |||
| 22 | #include "../Debug.h" | ||
| 23 | |||
| 24 | #include "../SessionTask.h" | ||
| 25 | #include "Signal.h" | ||
| 26 | #include "Main.h" | ||
| 27 | #include "SessionTaskData.h" | ||
| 28 | #include "../DataType.h" | ||
| 29 | |||
| 30 | ////////////////////////////////////////////////////////////////////// | ||
| 31 | const size_t Signal::dataTypeIndex[PdServ::DataType::maxWidth+1] = { | ||
| 32 | 3 /*0*/, 3 /*1*/, 2 /*2*/, 3 /*3*/, | ||
| 33 | 1 /*4*/, 3 /*5*/, 3 /*6*/, 3 /*7*/, 0 /*8*/ | ||
| 34 | }; | ||
| 35 | |||
| 36 | ////////////////////////////////////////////////////////////////////// | ||
| 37 | 942 | Signal::Signal( Task *task, | |
| 38 | size_t index, | ||
| 39 | unsigned int decimation, | ||
| 40 | const char *path, | ||
| 41 | const PdServ::DataType& dtype, | ||
| 42 | const void *addr, | ||
| 43 | size_t ndims, | ||
| 44 | 942 | const size_t *dim): | |
| 45 | PdServ::Signal(path, task, decimation, dtype, ndims, dim), | ||
| 46 | task(task), | ||
| 47 | addr(reinterpret_cast<const char *>(addr)), | ||
| 48 |
2/4✓ Branch 5 taken 942 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 942 times.
✗ Branch 10 not taken.
|
942 | index(index) |
| 49 | { | ||
| 50 | 942 | read_cb = copy; | |
| 51 | 942 | } | |
| 52 | |||
| 53 | ////////////////////////////////////////////////////////////////////// | ||
| 54 | 47 | void Signal::subscribe(PdServ::SessionTask *st) const | |
| 55 | { | ||
| 56 | // log_debug("%s", path.c_str()); | ||
| 57 | 47 | st->sessionTaskData->subscribe(this); | |
| 58 | 47 | } | |
| 59 | |||
| 60 | ////////////////////////////////////////////////////////////////////// | ||
| 61 | 44 | void Signal::unsubscribe(PdServ::SessionTask *st) const | |
| 62 | { | ||
| 63 | // log_debug("%s", path.c_str()); | ||
| 64 | 44 | st->sessionTaskData->unsubscribe(this); | |
| 65 | 44 | } | |
| 66 | |||
| 67 | ////////////////////////////////////////////////////////////////////// | ||
| 68 | 57 | int Signal::getValue(const PdServ::Session* /*session*/, | |
| 69 | void *dest, struct timespec *t) const | ||
| 70 | { | ||
| 71 | 57 | return task->main->getValue(this, dest, t); | |
| 72 | } | ||
| 73 | |||
| 74 | ////////////////////////////////////////////////////////////////////// | ||
| 75 | 1181 | const char *Signal::getValue(const PdServ::SessionTask* st) const | |
| 76 | { | ||
| 77 | 1181 | return st->sessionTaskData->getValue(this); | |
| 78 | } | ||
| 79 | |||
| 80 | ////////////////////////////////////////////////////////////////////// | ||
| 81 | 57 | void Signal::pollValue(void* dst, struct timespec* mtime) const | |
| 82 | { | ||
| 83 | 57 | task->getCurrentTime(mtime); | |
| 84 | |||
| 85 | 114 | read_cb(reinterpret_cast<const struct pdvariable*>( | |
| 86 | static_cast<const Variable*>(this)), | ||
| 87 | 57 | dst, addr, memSize, mtime, priv_data); | |
| 88 | 57 | } | |
| 89 | |||
| 90 | ////////////////////////////////////////////////////////////////////// | ||
| 91 | 57 | int Signal::copy(const struct pdvariable *, | |
| 92 | void *buf, const void *src, size_t len, | ||
| 93 | struct timespec*, void *) | ||
| 94 | { | ||
| 95 | // cout << __PRETTY_FUNCTION__ << checkOnly << endl; | ||
| 96 | 57 | std::copy( reinterpret_cast<const char*>(src), | |
| 97 | reinterpret_cast<const char*>(src)+len, | ||
| 98 | reinterpret_cast<char*>(buf)); | ||
| 99 | |||
| 100 | 57 | return 0; | |
| 101 | } | ||
| 102 |