forked from organicmaps/organicmaps
Added platform socket interface.
This commit is contained in:
parent
9fa9a1b656
commit
1f1cde5b12
4 changed files with 84 additions and 0 deletions
|
@ -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 \
|
||||
|
|
31
platform/socket.hpp
Normal file
31
platform/socket.hpp
Normal file
|
@ -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
|
43
platform/socket_apple.mm
Normal file
43
platform/socket_apple.mm
Normal file
|
@ -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
|
|
@ -7,6 +7,8 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
34C624BD1DABCCD100510300 /* socket_apple.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34C624BB1DABCCD100510300 /* socket_apple.mm */; };
|
||||
34C624BE1DABCCD100510300 /* socket.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34C624BC1DABCCD100510300 /* socket.hpp */; };
|
||||
3D30587D1D8320E4004AC712 /* http_client.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D30587B1D8320E4004AC712 /* http_client.hpp */; };
|
||||
3D30587F1D880910004AC712 /* http_client_apple.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3D30587E1D880910004AC712 /* http_client_apple.mm */; };
|
||||
3D97F64B1D9C05E800380945 /* http_client.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D97F64A1D9C05E800380945 /* http_client.cpp */; };
|
||||
|
@ -98,6 +100,8 @@
|
|||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
34C624BB1DABCCD100510300 /* socket_apple.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = socket_apple.mm; sourceTree = "<group>"; };
|
||||
34C624BC1DABCCD100510300 /* socket.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = socket.hpp; sourceTree = "<group>"; };
|
||||
3D30587B1D8320E4004AC712 /* http_client.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = http_client.hpp; sourceTree = "<group>"; };
|
||||
3D30587E1D880910004AC712 /* http_client_apple.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = http_client_apple.mm; sourceTree = "<group>"; };
|
||||
3D97F64A1D9C05E800380945 /* http_client.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_client.cpp; sourceTree = "<group>"; };
|
||||
|
@ -302,6 +306,8 @@
|
|||
6753437A1A3F5CF500A0A8C3 /* platform */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
34C624BB1DABCCD100510300 /* socket_apple.mm */,
|
||||
34C624BC1DABCCD100510300 /* socket.hpp */,
|
||||
3D97F64A1D9C05E800380945 /* http_client.cpp */,
|
||||
3D30587E1D880910004AC712 /* http_client_apple.mm */,
|
||||
3D30587B1D8320E4004AC712 /* http_client.hpp */,
|
||||
|
@ -402,6 +408,7 @@
|
|||
67AB92EB1B7B3E9100AB5194 /* get_text_by_id.hpp in Headers */,
|
||||
675343D41A3F5D5A00A0A8C3 /* settings.hpp in Headers */,
|
||||
675343B51A3F5D5A00A0A8C3 /* constants.hpp in Headers */,
|
||||
34C624BE1DABCCD100510300 /* socket.hpp in Headers */,
|
||||
675343C11A3F5D5A00A0A8C3 /* location_service.hpp in Headers */,
|
||||
67AB92DD1B7B3D7300AB5194 /* mwm_version.hpp in Headers */,
|
||||
675343CA1A3F5D5A00A0A8C3 /* platform_unix_impl.hpp in Headers */,
|
||||
|
@ -564,6 +571,7 @@
|
|||
6741250C1B4C00CC00A3E828 /* local_country_file_utils.cpp in Sources */,
|
||||
3D97F64B1D9C05E800380945 /* http_client.cpp in Sources */,
|
||||
67AB92EA1B7B3E9100AB5194 /* get_text_by_id.cpp in Sources */,
|
||||
34C624BD1DABCCD100510300 /* socket_apple.mm in Sources */,
|
||||
671C62061AE9014C00076BD0 /* measurement_utils.cpp in Sources */,
|
||||
675343B61A3F5D5A00A0A8C3 /* http_request.cpp in Sources */,
|
||||
675343CC1A3F5D5A00A0A8C3 /* platform.cpp in Sources */,
|
||||
|
|
Loading…
Add table
Reference in a new issue