annotate vamp-client/SynchronousTransport.h @ 296:50a0b4fea7f1 tip master

Merge pull request #8 from michel-slm/gcc15 Include headers needed to compile with GCC 15's -std=gnu23 default
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 27 Jan 2025 08:53:58 +0000
parents ce42f0bebae3
children
rev   line source
c@118 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@118 2 /*
c@118 3 Piper C++
c@118 4
c@118 5 An API for audio analysis and feature extraction plugins.
c@118 6
c@118 7 Centre for Digital Music, Queen Mary, University of London.
c@118 8 Copyright 2006-2016 Chris Cannam and QMUL.
c@118 9
c@118 10 Permission is hereby granted, free of charge, to any person
c@118 11 obtaining a copy of this software and associated documentation
c@118 12 files (the "Software"), to deal in the Software without
c@118 13 restriction, including without limitation the rights to use, copy,
c@118 14 modify, merge, publish, distribute, sublicense, and/or sell copies
c@118 15 of the Software, and to permit persons to whom the Software is
c@118 16 furnished to do so, subject to the following conditions:
c@118 17
c@118 18 The above copyright notice and this permission notice shall be
c@118 19 included in all copies or substantial portions of the Software.
c@118 20
c@118 21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c@118 22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c@118 23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c@118 24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
c@118 25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
c@118 26 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
c@118 27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
c@118 28
c@118 29 Except as contained in this notice, the names of the Centre for
c@118 30 Digital Music; Queen Mary, University of London; and Chris Cannam
c@118 31 shall not be used in advertising or otherwise to promote the sale,
c@118 32 use or other dealings in this Software without prior written
c@118 33 authorization.
c@118 34 */
c@90 35
c@90 36 #ifndef PIPER_SYNCHRONOUS_TRANSPORT_H
c@90 37 #define PIPER_SYNCHRONOUS_TRANSPORT_H
c@90 38
c@90 39 #include <vector>
c@92 40 #include <cstdlib>
c@121 41 #include <stdexcept>
c@90 42
c@97 43 namespace piper_vamp {
c@97 44 namespace client {
c@90 45
c@92 46 class MessageCompletenessChecker // interface
c@92 47 {
c@92 48 public:
c@146 49 enum State { Complete, Incomplete, Invalid };
c@146 50
c@92 51 virtual ~MessageCompletenessChecker() = default;
c@146 52 virtual State check(const std::vector<char> &message) const = 0;
c@92 53 };
c@92 54
c@134 55 class LogCallback
c@134 56 {
c@134 57 public:
c@134 58 virtual ~LogCallback() { }
cannam@282 59
cannam@282 60 /**
cannam@282 61 * Log a message. The logger should terminate the message
cannam@282 62 * appropriately after logging; the caller is not expected to end
cannam@282 63 * it with \n or similar.
cannam@282 64 */
c@134 65 virtual void log(std::string) const = 0;
c@134 66 };
c@134 67
c@90 68 class SynchronousTransport // interface
c@90 69 {
c@90 70 public:
c@92 71 virtual ~SynchronousTransport() = default;
c@92 72
c@126 73 /**
c@126 74 * Set a completeness checker object. The caller retains ownership
c@126 75 * of the checker and must ensure its lifespan outlives the transport.
c@126 76 */
c@92 77 virtual void setCompletenessChecker(MessageCompletenessChecker *) = 0;
c@90 78
c@126 79 /**
c@126 80 * Make a synchronous call, passing a serialised request in the data array
c@126 81 * of length bytes, and return the result.
c@126 82 *
c@134 83 * The type field is only used for logging and debug output.
c@134 84 *
c@126 85 * The slow flag is a hint that the recipient may take longer than usual
c@126 86 * to process this request and so the caller may wish to be more relaxed
c@126 87 * about idling to wait for the reply. (This shouldn't make any difference
c@126 88 * with a sensible blocking network API, but you never know...)
c@126 89 *
c@126 90 * May throw ServerCrashed if the server endpoint disappeared during the
c@126 91 * call. Throws std::logic_error if isOK() is not true at the time of
c@126 92 * calling, so check that before you call.
c@126 93 */
c@134 94 virtual std::vector<char> call(const char *data, size_t bytes,
c@134 95 std::string type, bool slow) = 0;
c@126 96
c@126 97 /**
c@126 98 * Check whether the transport was initialised correctly and is working.
c@126 99 * This will return false if the endpoint could not be initialised or
c@126 100 * the endpoint service has crashed or become unavailable. Always check
c@126 101 * this before using call().
c@126 102 */
c@90 103 virtual bool isOK() const = 0;
c@90 104 };
c@90 105
c@90 106 }
c@94 107 }
c@90 108
c@90 109 #endif