Files
pip/libs/main/cloud/picloudclient.h

130 lines
4.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! \file picloudclient.h
//! \ingroup Cloud
//! \brief
//! \~english PICloud Client
//! \~russian Клиент PICloud
//! \details
//! \~english Client implementation for connecting to PICloud servers over TCP.
//! \~russian Реализация клиента для подключения к серверам PICloud по TCP.
/*
PIP - Platform Independent Primitives
PICloud Client
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PICLOUDCLIENT_H
#define PICLOUDCLIENT_H
#include "picloudbase.h"
#include "piconditionvar.h"
//! \brief PICloud client implementation
//! \~english PICloud client for connecting to servers
//! \~russian Клиент PICloud для подключения к серверам
class PIP_CLOUD_EXPORT PICloudClient
: public PIIODevice
, public PICloudBase {
PIIODEVICE(PICloudClient, "");
public:
//! \brief
//! \~english Constructs PICloudClient
//! \~russian Создает PICloudClient
explicit PICloudClient(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
//! \brief
//! \~english Destructor
//! \~russian Деструктор
virtual ~PICloudClient();
//! \brief
//! \~english Sets server name
//! \~russian Устанавливает имя сервера
void setServerName(const PIString & server_name);
//! \brief
//! \~english Sets keep connection mode
//! \~russian Устанавливает режим поддержания соединения
void setKeepConnection(bool on);
//! \brief
//! \~english Checks if connected to server
//! \~russian Проверяет подключение к серверу
bool isConnected() const { return is_connected; }
//! \brief
//! \~english Returns number of bytes available
//! \~russian Возвращает количество доступных байт
ssize_t bytesAvailable() const override { return buff.size(); }
//! \brief
//! \~english Interrupts connection
//! \~russian Прерывает соединение
void interrupt() override;
//! \brief
//! \~english Raised when connected to server
//! \~russian Вызывается при подключении к серверу
EVENT(connected);
//! \brief
//! \~english Raised when disconnected from server
//! \~russian Вызывается при отключении от сервера
EVENT(disconnected);
protected:
//! \brief
//! \~english Opens device
//! \~russian Открывает устройство
bool openDevice() override;
//! \brief
//! \~english Closes device
//! \~russian Закрывает устройство
bool closeDevice() override;
//! \brief
//! \~english Reads data from device
//! \~russian Читает данные из устройства
ssize_t readDevice(void * read_to, ssize_t max_size) override;
//! \brief
//! \~english Writes data to device
//! \~russian Записывает данные в устройство
ssize_t writeDevice(const void * data, ssize_t size) override;
//! \brief
//! \~english Returns device info flags
//! \~russian Возвращает флаги информации об устройстве
DeviceInfoFlags deviceInfoFlags() const override { return PIIODevice::Reliable; }
private:
EVENT_HANDLER1(void, _readed, PIByteArray &, data);
void internalDisconnect();
PIByteArray buff;
PIMutex mutex_buff;
PIMutex mutex_connect;
PIConditionVariable cond_buff;
PIConditionVariable cond_connect;
std::atomic_bool is_connected;
std::atomic_bool is_deleted;
};
#endif // PICLOUDCLIENT_H