diff options
author | Ilya Grechuhin <i.grechuhin@gmail.com> | 2016-10-10 17:22:32 +0300 |
---|---|---|
committer | Ilya Grechuhin <i.grechuhin@gmail.com> | 2016-10-10 17:28:12 +0300 |
commit | 1f1cde5b12946fd64eb6a3c8424cdbf8e352e81a (patch) | |
tree | d24e1bdce0eb6ad53a43fd3916724663bec621db /platform | |
parent | 9fa9a1b656a7703c50a557a108c77b0c41ec53d5 (diff) |
Added platform socket interface.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/platform.pro | 2 | ||||
-rw-r--r-- | platform/socket.hpp | 31 | ||||
-rw-r--r-- | platform/socket_apple.mm | 43 |
3 files changed, 76 insertions, 0 deletions
diff --git a/platform/platform.pro b/platform/platform.pro index 66f5e60527..d05cc1f1e4 100644 --- a/platform/platform.pro +++ b/platform/platform.pro @@ -50,6 +50,7 @@ macx-*|iphone* { OBJECTIVE_SOURCES += \ http_thread_apple.mm \ http_client_apple.mm \ + socket_apple.mm \ QMAKE_OBJECTIVE_CFLAGS += -fobjc-arc } @@ -85,6 +86,7 @@ HEADERS += \ preferred_languages.hpp \ servers_list.hpp \ settings.hpp \ + socket.hpp \ SOURCES += \ chunks_download_strategy.cpp \ diff --git a/platform/socket.hpp b/platform/socket.hpp new file mode 100644 index 0000000000..92a7b74d07 --- /dev/null +++ b/platform/socket.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "std/string.hpp" +#include "std/target_os.hpp" + +#if defined(OMIM_OS_IPHONE) || defined(OMIM_OS_MAC) +@class SocketImpl; +#else +class SocketImpl; +#endif + +namespace platform +{ +class Socket +{ +public: + Socket(); + ~Socket(); + + bool Open(string const & host, uint16_t port); + void Close(); + + bool Read(uint8_t * data, uint32_t count); + bool Write(uint8_t const * data, uint32_t count); + + void SetTimeout(uint32_t milliseconds); + +private: + SocketImpl * m_socketImpl = nullptr; +}; +} // namespace platform diff --git a/platform/socket_apple.mm b/platform/socket_apple.mm new file mode 100644 index 0000000000..57dd0ebc18 --- /dev/null +++ b/platform/socket_apple.mm @@ -0,0 +1,43 @@ +#include "socket.hpp" + +#import <Foundation/Foundation.h> + +@interface SocketImpl : NSObject + +- (BOOL)open:(NSString *)host port:(NSUInteger)port; +- (void)close; + +- (BOOL)read:(uint8_t *)data count:(NSUInteger)count; +- (BOOL)write:(uint8_t const *)data count:(NSUInteger)count; + +@end + +@implementation SocketImpl + +- (BOOL)open:(NSString *)host port:(NSUInteger)port { return YES; } +- (void)close {} +- (BOOL)read:(uint8_t *)data count:(NSUInteger)count { return YES; } +- (BOOL)write:(uint8_t const *)data count:(NSUInteger)count { return YES; } +@end + +namespace platform +{ +Socket::Socket() { m_socketImpl = [[SocketImpl alloc] init]; } +Socket::~Socket() +{ + Close(); + m_socketImpl = nil; +} + +bool Socket::Open(string const & host, uint16_t port) +{ + return [m_socketImpl open:@(host.c_str()) port:port]; +} + +void Socket::Close() { [m_socketImpl close]; } +bool Socket::Read(uint8_t * data, uint32_t count) { return [m_socketImpl read:data count:count]; } +bool Socket::Write(uint8_t const * data, uint32_t count) +{ + return [m_socketImpl write:data count:count]; +} +} // namespace platform |