summaryrefslogtreecommitdiff
path: root/include/mts/MTS_IO_Connection.h
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2015-04-20 17:14:31 -0500
committerJesse Gilles <jgilles@multitech.com>2015-04-20 17:14:31 -0500
commitd84d880627bcc1e1898a8f96b861bc25863ec86c (patch)
treee7db4eef6a8e8254eaa6ba0c7e5d56098af19d16 /include/mts/MTS_IO_Connection.h
downloadlibmts-io-d84d880627bcc1e1898a8f96b861bc25863ec86c.tar.gz
libmts-io-d84d880627bcc1e1898a8f96b861bc25863ec86c.tar.bz2
libmts-io-d84d880627bcc1e1898a8f96b861bc25863ec86c.zip
initial commit
Diffstat (limited to 'include/mts/MTS_IO_Connection.h')
-rw-r--r--include/mts/MTS_IO_Connection.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/include/mts/MTS_IO_Connection.h b/include/mts/MTS_IO_Connection.h
new file mode 100644
index 0000000..bd4b32f
--- /dev/null
+++ b/include/mts/MTS_IO_Connection.h
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2015 by Multi-Tech Systems
+ *
+ * This file is part of libmts_io.
+ *
+ * libmts_io is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * libmts_io is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libmts_io. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/*!
+ \file MTS_IO_Connection.h
+ \brief A brief description
+ \date Jan 15, 2013
+ \author sgodinez
+
+ A more elaborate description
+*/
+
+#ifndef MTS_IO_CONNECTION_H_
+#define MTS_IO_CONNECTION_H_
+
+#include <mts/MTS_AutoPtr.h>
+#include <mts/MTS_Lock.h>
+#include <mts/MTS_NonCopyable.h>
+#include <string>
+
+namespace MTS {
+
+ class Buffer;
+
+ namespace IO {
+ class Connection : public MTS::NonCopyable {
+
+ private:
+ static int32_t BLOCKING;
+
+ public:
+
+ virtual ~Connection();
+
+ const std::string& getName() const;
+
+ bool open(const int32_t& timeoutMillis = 1000);
+ void close();
+ bool isClosed() const;
+
+ void setCloseable(bool bCloseable);
+ bool isCloseable() const;
+
+ int read(char* pBuffer, const uint32_t& iSize, int32_t& timeoutMillis = BLOCKING);
+ int read(std::string& sBuffer, const uint32_t& iSize, int32_t& timeoutMillis = BLOCKING);
+ int read(Buffer& oBuffer, const uint32_t& iSize, int32_t& timeoutMillis = BLOCKING);
+
+ int write(const char* pBuffer, const uint32_t& iSize, int32_t& timeoutMillis = BLOCKING);
+ int write(const std::string& sBuffer, const uint32_t& iSize, int32_t& timeoutMillis = BLOCKING);
+ int write(const Buffer& oBuffer, const uint32_t& iSize, int32_t& timeoutMillis = BLOCKING);
+
+
+
+ protected:
+ explicit Connection(const std::string& sName);
+
+ private:
+ const std::string m_sName;
+ bool m_bClosed;
+ bool m_bCloseable;
+ AutoPtr<Lock> m_apLock;
+ AutoPtr<Lock> m_apReadLock;
+ AutoPtr<Lock> m_apWriteLock;
+
+ /*! Opens the connection
+ * \return true if the connection has been opened, false otherwise
+ */
+ virtual bool doOpen(const int32_t& timeoutMillis) = 0;
+
+ /*! Closes the connection
+ */
+ virtual void doClose() = 0;
+
+ /*! Perform read from connection
+ * \param pBuffer the buffer allocated for read bytes
+ * \param iSize the number of bytes to be read. the size allocated for pBuffer must be greater or equal to iSize
+ * \param timeoutMillis the amount of time to attempt to read iSize bytes. less than zero will block until iSize bytes has been read
+ * \return the number of bytes read. -1 for error
+ */
+ virtual int doRead(char* pBuffer, const uint32_t& iSize, int32_t& timeoutMillis) = 0;
+
+ /*! Perform write to connection
+ * \param pBuffer the buffer that contains the data to be written
+ * \param iSize the number of bytes to be written
+ * \param timeoutMillis the amount of time to attempt to write iSize bytes. less than zero will block until iSize bytes has been written
+ * \return the number of bytes written. -1 for error
+ */
+ virtual int doWrite(const char* pBuffer, const uint32_t& iSize, int32_t& timeoutMillis) = 0;
+
+ };
+ }
+}
+
+
+
+#endif /* MTS_IO_CONNECTION_H_ */