-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
190 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../src/realm_dart_http_transport.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule realm-core
updated
43 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2022 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "realm_dart_http_transport.h" | ||
#include "dart_api_dl.h" | ||
|
||
struct HandleScope { | ||
HandleScope() { | ||
Dart_EnterScope_DL(); | ||
} | ||
|
||
~HandleScope() { | ||
Dart_ExitScope_DL(); | ||
} | ||
}; | ||
|
||
class RequestCallbackData { | ||
static void finalize_handle(void* isolate_callback_data, void* peer) { | ||
auto request_callback_data = static_cast<RequestCallbackData*>(peer); | ||
request_callback_data->delete_handle(); | ||
} | ||
|
||
void delete_handle() { | ||
if (m_handle) { | ||
Dart_DeleteWeakPersistentHandle_DL(m_handle); | ||
m_handle = nullptr; | ||
} | ||
} | ||
|
||
public: | ||
RequestCallbackData(Dart_Handle handle, realm_dart_http_request_func_t callback) | ||
: m_handle(Dart_NewWeakPersistentHandle_DL(handle, nullptr, 1, finalize_handle)), m_callback(callback) | ||
{} | ||
|
||
~RequestCallbackData() { | ||
delete_handle(); | ||
} | ||
|
||
void callback(const realm_http_request_t request, void* request_context) { | ||
if (m_handle) { | ||
HandleScope scope; | ||
auto handle = Dart_HandleFromWeakPersistent_DL(m_handle); | ||
m_callback(handle, request, request_context); | ||
} | ||
} | ||
|
||
private: | ||
Dart_WeakPersistentHandle m_handle; | ||
realm_dart_http_request_func_t m_callback; | ||
}; | ||
|
||
void free_request_callback_data(void* userdata) { | ||
auto request_callback_data = static_cast<RequestCallbackData*>(userdata); | ||
delete request_callback_data; | ||
} | ||
|
||
void on_request_callback( | ||
void* userdata, | ||
const realm_http_request_t request, | ||
void* request_context) | ||
{ | ||
auto request_callback_data = static_cast<RequestCallbackData*>(userdata); | ||
request_callback_data->callback(request, request_context); | ||
} | ||
|
||
RLM_API realm_http_transport_t* realm_dart_http_transport_new( | ||
realm_dart_http_request_func_t request_callback, | ||
Dart_Handle userdata) | ||
{ | ||
auto request_callback_data = new RequestCallbackData(userdata, request_callback); | ||
return realm_http_transport_new(on_request_callback, request_callback_data, free_request_callback_data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2022 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef REALM_DART_HTTP_TRANSPORT_H | ||
#define REALM_DART_HTTP_TRANSPORT_H | ||
|
||
#include "realm.h" | ||
#include "dart_api_dl.h" | ||
|
||
/** | ||
* Callback function used by Core to make a HTTP request. | ||
* | ||
* Complete the request by calling realm_dart_http_transport_complete_request(), | ||
* passing in the request_context pointer here and the received response. | ||
* Network request are expected to be asynchronous and can be completed on any thread. | ||
* | ||
* @param userdata The userdata pointer passed to realm_dart_http_transport_new(). | ||
* @param request The request to send. | ||
* @param request_context Internal state pointer of Core, needed by realm_http_transport_complete_request(). | ||
*/ | ||
typedef void (*realm_dart_http_request_func_t)(Dart_Handle userdata, const realm_http_request_t request, void* request_context); | ||
|
||
/** | ||
* Create a new HTTP transport with these callbacks implementing its functionality. | ||
* | ||
* This is a dart specific wrapper for realm_http_transport_new. | ||
*/ | ||
RLM_API realm_http_transport_t* realm_dart_http_transport_new(realm_dart_http_request_func_t request_callback, | ||
Dart_Handle userdata); | ||
|
||
#endif |