Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-10137: BlackBerry: Implement Ti.Network.Socket and Ti.Network.Socket.TCP [part2] #134

Merged
28 changes: 14 additions & 14 deletions apidoc/Titanium/Network/Socket/TCP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,23 @@ properties:
- name: host
type: String
summary: The host to connect to or listen on.
platforms: [android, iphone, ipad, blackberry]
platforms: [android, iphone, ipad, blackberry]
description: |
Can only be modified when this socket is in the [INITIALIZED](Titanium.Network.Socket.INITIALIZED) state.

Supports both IPv4 and IPv6 addresses.
- name: port
type: Number
summary: The port to connect to or listen on.
platforms: [android, iphone, ipad, blackberry]
platforms: [android, iphone, ipad, blackberry]
description: |
Can only be modified when this socket is in the [INITIALIZED](Titanium.Network.Socket.INITIALIZED) state.

- name: listenQueueSize
type: Number
summary: Max number of pending incoming connections to be allowed when the socket is
in the [LISTENING](Titanium.Network.Socket.LISTENING) state.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]
description: |
Any incoming connections received while the max number of pending connections has
been reached will be rejected.
Expand All @@ -199,7 +199,7 @@ properties:
- name: connected
type: Callback<ConnectedCallbackArgs>
summary: Callback to be fired when the socket enters the "connected" state.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]
description: |
Only invoked following a successful [connect](Titanium.Network.Socket.TCP.connect)
call.
Expand All @@ -208,18 +208,18 @@ properties:
- name: error
type: Callback<ErrorCallbackArgs>
summary: Callback to be fired when the socket enters the [ERROR](Titanium.Network.Socket.ERROR) state.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]

- name: accepted
type: Callback<AcceptedCallbackArgs>
summary: Callback to be fired when a listener accepts a connection.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]

- name: state
type: Number
permission: read-only
summary: Current state of the socket.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]
description: |
One of: [INITIALIZED](Titanium.Network.Socket.INITIALIZED),
[CONNECTED](Titanium.Network.Socket.CONNECTED),
Expand All @@ -231,7 +231,7 @@ properties:
methods:
- name: connect
summary: Attempts to connect the socket to its host/port.
platforms: [android, iphone, ipad, blackberry]
platforms: [android, iphone, ipad, blackberry]
description: |
Throws an exception if the socket is in a [CONNECTED](Titanium.Network.Socket.CONNECTED)
or [LISTENING](Titanium.Network.Socket.LISTENING) state.
Expand All @@ -241,7 +241,7 @@ methods:

- name: listen
summary: Attempts to start listening on the socket's host/port.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]
description: |
The `listen` call will attempt to listen on the specified host and/or port
property for the socket if they are set.
Expand All @@ -258,7 +258,7 @@ methods:

- name: accept
summary: Tells a [LISTENING](Titanium.Network.Socket.LISTENING) socket to accept a connection request at the top of a listener's request queue when one becomes available.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]
description: |
Nonblocking; if there are no connections in the queue, sets a flag so that
the socket accepts the next incoming connection immediately.
Expand Down Expand Up @@ -286,15 +286,15 @@ methods:

- name: close
summary: Closes a socket.
platforms: [android, iphone, ipad, blackberry]
platforms: [android, iphone, ipad, blackberry]
description: |
Throws exception if the socket is not in a [CONNECTED](Titanium.Network.Socket.CONNECTED)
or [LISTENING](Titanium.Network.Socket.LISTENING) state. Blocking.

---
name: ConnectedCallbackArgs
summary: Argument object passed to the [connected](Titanium.Network.Socket.TCP.connected) callback when the socket connects.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]
description: |
Only invoked following a successful [connect](Titanium.Network.Socket.TCP.connect)
call.
Expand All @@ -309,7 +309,7 @@ properties:
name: ErrorCallbackArgs
summary: Object passed to the error callback when the socket enters
the [ERROR](Titanium.Network.Socket.ERROR) state.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]
since: "1.7"

properties:
Expand All @@ -330,7 +330,7 @@ name: AcceptedCallbackArgs
summary: |
Argument object passed to the [accepted](Titanium.Network.Socket.TCP.accepted)
callback when a listener accepts a connection.
platforms: [android, iphone, ipad]
platforms: [android, iphone, ipad, blackberry]
since: "1.7"

properties:
Expand Down
10 changes: 10 additions & 0 deletions blackberry/tibb/NativeBufferObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ int NativeBufferObject::insert(NativeBufferObject* sourceBuffer, int offset, int
return bytesWritten;
}

int NativeBufferObject::bufferSize() const
{
return internalData_.size();
}

void NativeBufferObject::replaceInternalData(const QByteArray& newArray, int offset, int length)
{
internalData_ = internalData_.replace(offset, length, newArray);
}

const static NATIVE_PROPSETGET_SETTING g_BufferPropSetGet[] =
{
{N_BUFFER_PROP_BYTEORDER, PROP_SETGET_FUNCTION(setByteOrder), PROP_SETGET_FUNCTION(getByteOrder)},
Expand Down
2 changes: 2 additions & 0 deletions blackberry/tibb/NativeBufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class NativeBufferObject : public NativeProxyObject
int append(NativeBufferObject* sourceBuffer, int sourceOffset = -1, int sourceLength = -1);
NativeBufferObject* clone(int sourceOffset = -1, int sourceLength = -1);
int insert(NativeBufferObject* sourceBuffer, int offset, int sourceOffset = -1, int sourceLength = -1);
int bufferSize() const;
void replaceInternalData(const QByteArray& newArray, int offset, int length);

protected:
virtual ~NativeBufferObject();
Expand Down
4 changes: 3 additions & 1 deletion blackberry/tibb/NativeMessageStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ N_MESSAGESTRINGS_CONST_DEF(char*, Failed_to_open_database, "Failed to open datab
N_MESSAGESTRINGS_CONST_DEF(char*, Failed_to_remove_key, "Failed to remove key (%1, %2): %3");
N_MESSAGESTRINGS_CONST_DEF(char*, Failed_to_set_key, "Failed to set key (%1, %2): %3");
N_MESSAGESTRINGS_CONST_DEF(char*, INTERNAL__An_error_occurred_while_parsing_the_format_string, "INTERNAL: An error occurred while parsing the format string");
N_MESSAGESTRINGS_CONST_DEF(char*, Invalid_hostname_or_port, "Invalid host name or port");
N_MESSAGESTRINGS_CONST_DEF(char*, Invalid_socket_state, "Invalid socket state");
N_MESSAGESTRINGS_CONST_DEF(char*, Numbered_argument_exceeds_the_length_of_provided_arguments, "Numbered argument exceeds the length of provided arguments");
N_MESSAGESTRINGS_CONST_DEF(char*, Out_of_bounds, "Out of bounds");
N_MESSAGESTRINGS_CONST_DEF(char*, Unknown_key_value_received, "Unknown key:value received");
N_MESSAGESTRINGS_CONST_DEF(char*, Unknown_value_received, "Unknown value received");
N_MESSAGESTRINGS_CONST_DEF(char*, Unsupported_event_name_, "Unsupported event name ");

N_MESSAGESTRINGS_CONST_DEF(char*, Write_operation_failure, "Write operation failed: %1");
}
}

Expand Down