#ifndef SRC_SERVICE_PROTOCOL_PROTOCOL_H_
#define SRC_SERVICE_PROTOCOL_PROTOCOL_H_
+#include <memory>
+
#include <common.h>
+
#include <request/Request.h>
#include <response/CheckResponse.h>
virtual void appendResponseToBuffer(CheckResponse &&response);
};
+typedef std::shared_ptr<Protocol> ProtocolPtr;
+
} // namespace Cynara
#endif /* SRC_SERVICE_PROTOCOL_PROTOCOL_H_ */
return Cynara::getSocketManager()->descriptor(fd).writeQueue();
}
-Protocol *RequestContext::protocol(int fd) {
+ProtocolPtr RequestContext::protocol(int fd) {
return Cynara::getSocketManager()->descriptor(fd).protocol();
}
namespace Cynara {
-class Protocol;
-
class RequestContext {
public:
static BinaryQueue &resultQueue(int fd);
- static Protocol *protocol(int fd);
+ static ProtocolPtr protocol(int fd);
};
} // namespace Cynara
m_readQueue.clear();
m_writeQueue.clear();
m_writeBuffer.clear();
- m_protocol = nullptr;
+ m_protocol.reset();
}
} // namespace Cynara
#ifndef SRC_SERVICE_SOCKETS_DESCRIPTOR_H_
#define SRC_SERVICE_SOCKETS_DESCRIPTOR_H_
+#include <memory>
+
#include <common.h>
#include <protocol/Protocol.h>
BinaryQueue m_writeQueue;
RawBuffer m_writeBuffer;
- Protocol *m_protocol;
+ ProtocolPtr m_protocol;
public:
Descriptor();
bool hasDataToWrite(void) const;
- Protocol *protocol(void) {
+ ProtocolPtr protocol(void) {
return m_protocol;
}
return m_writeQueue;
}
- void setProtocol(Protocol *protocol) {
+ void setProtocol(ProtocolPtr protocol) {
m_protocol = protocol;
}
const mode_t clientSocketUMask(0);
const mode_t adminSocketUMask(0077);
- createDomainSocket(new ProtocolClient, clientSocketPath, clientSocketUMask);
- createDomainSocket(new ProtocolAdmin, adminSocketPath, adminSocketUMask);
+ createDomainSocket(ProtocolPtr(new ProtocolClient), clientSocketPath, clientSocketUMask);
+ createDomainSocket(ProtocolPtr(new ProtocolAdmin), adminSocketPath, adminSocketUMask);
// todo create signal descriptor
LOGI("SocketManger init done");
}
return true;
}
-void SocketManager::createDomainSocket(Protocol *protocol, const std::string &path, mode_t mask) {
+void SocketManager::createDomainSocket(ProtocolPtr protocol, const std::string &path, mode_t mask) {
int fd = getSocketFromSystemD(path);
if (fd == -1)
fd = createDomainSocketHelp(path, mask);
#define SRC_SERVICE_SOCKETS_SOCKETMANAGER_H_
#include <vector>
+#include <memory>
#include <stdio.h>
#include <common.h>
void closeSocket(int fd);
bool handleRead(int fd, const RawBuffer &readbuffer);
- void createDomainSocket(Protocol *protocol, const std::string &path, mode_t mask);
+ void createDomainSocket(ProtocolPtr protocol, const std::string &path, mode_t mask);
int createDomainSocketHelp(const std::string &path, mode_t mask);
int getSocketFromSystemD(const std::string &path);