-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
1 parent
f633e43
commit 6ba0d13
Showing
3 changed files
with
158 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# | ||
# Copyright (c) 2024 Project CHIP Authors | ||
# All rights reserved. | ||
# | ||
# 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. | ||
# | ||
|
||
import ctypes | ||
from ctypes import CFUNCTYPE, POINTER, c_bool, c_char_p, c_size_t, c_uint8, c_uint16, c_uint32, c_void_p, cast, py_object | ||
|
||
|
||
_OnTransferObtainedCallbackFunct = CFUNCTYPE( | ||
None, py_object, PyChipError, c_void_p, c_uint8, c_uint16, c_uint64, c_uint64, c_uint8_p, c_uint16, c_uint8_p, c_size_t) | ||
_OnDataReceivedCallbackFunct = CFUNCTYPE( | ||
None, py_object, c_uint16, c_uint8, PyChipError) | ||
_OnTransferCompletedCallbackFunct = CFUNCTYPE( | ||
None, py_object, PyChipError) | ||
|
||
|
||
@_OnTransferObtainedCallbackFunct | ||
def _OnTransferObtainedCallback(closure, result: PyChipError, bdxTransfer, transferControlFlags: int, maxBlockSize: int, | ||
startOffset: int, length: int, fileDesignator, fileDesignatorLength: int, metadata, | ||
metadataLength: int): | ||
# TODO: Call the closure with the rest of the parameters. | ||
pass | ||
|
||
|
||
@_OnDataReceivedCallbackFunct | ||
def _OnDataReceivedCallback(closure, dataBuffer, bufferLength: int): | ||
# TODO: Call the closure with the data. | ||
pass | ||
|
||
|
||
@_OnTransferCompletedCallbackFunct | ||
def _OnTransferCompletedCallback(closure, result: PyChipError): | ||
# TODO: Call the closure. | ||
pass | ||
|
||
|
||
def Init(): | ||
handle = chip.native.GetLibraryHandle() | ||
# Uses one of the type decorators as an indicator for everything being initialized. | ||
if not handle.pychip_Bdx_ExpectBdxTransfer.argtypes: | ||
setter = chip.native.NativeLibraryHandleMethodArguments(handle) | ||
|
||
setter.Set('pychip_Bdx_ExpectBdxTransfer', | ||
PyChipError, []) | ||
setter.Set('pychip_Bdx_StopExpectingBdxTransfer', | ||
PyChipError, []) | ||
setter.Set('pychip_Bdx_AcceptSendTransfer', | ||
PyChipError, [c_void_p, py_object, py_object]) | ||
setter.Set('pychip_Bdx_AcceptReceiveTransfer', | ||
PyChipError, [c_void_p, c_uint8_p, c_size_t]) | ||
setter.Set('pychip_Bdx_RejectTransfer', | ||
PyChipError, [c_void_p]) | ||
setter.Set('pychip_Bdx_InitCallbacks', None, [ | ||
_OnTransferObtainedCallbackFunct, _OnDataReceivedCallbackFunct, _OnTransferCompletedCallbackFunct]) | ||
|
||
handle.pychip_Bdx_InitCallbacks( | ||
_OnTransferObtainedCallback, _OnDataReceivedCallback, _OnTransferCompletedCallback) |
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,86 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* 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 <protocols/bdx/BdxMessages.h> | ||
|
||
#include <controller/python/chip/native/PyChipError.h> | ||
|
||
using PyObject = void *; | ||
|
||
namespace chip { | ||
namespace python { | ||
|
||
using OnTransferObtainedCallback = void (*)(PyObject context, PyChipError result, void * bdxTransfer, | ||
bdx::TransferControlFlags transferControlFlags, uint16_t maxBlockSize, | ||
uint64_t startOffset, uint64_t length, const uint8_t * fileDesignator, | ||
uint16_t fileDesignatorLength, const uint8_t * metadata, size_t metadataLength); | ||
using OnDataReceivedCallback = void (*)(PyObject context, const uint8_t * dataBuffer, size_t bufferLength); | ||
using OnTransferCompletedCallback = void (*)(PyObject context, PyChipError result); | ||
|
||
OnTransferObtainedCallback gOnTransferObtainedCallback = nullptr; | ||
OnDataReceivedCallback gOnDataReceivedCallback = nullptr; | ||
OnTransferCompletedCallback gOnTransferCompletedCallback = nullptr; | ||
|
||
} // namespace python | ||
} // namespace chip | ||
|
||
using namespace chip::python; | ||
|
||
extern "C" { | ||
|
||
void pychip_Bdx_InitCallbacks(OnTransferObtainedCallback onTransferObtainedCallback, | ||
OnDataReceivedCallback onDataReceivedCallback, | ||
OnTransferCompletedCallback onTransferCompletedCallback) | ||
{ | ||
OnTransferObtainedCallback gOnTransferObtainedCallback = onTransferObtainedCallback; | ||
OnDataReceivedCallback gOnDataReceivedCallback = onDataReceivedCallback; | ||
OnTransferCompletedCallback gOnTransferCompletedCallback = onTransferCompletedCallback; | ||
} | ||
|
||
PyChipError pychip_Bdx_ExpectBdxTransfer() | ||
{ | ||
// TODO: Call BdxTransferManager::ExpectATransfer. | ||
} | ||
|
||
PyChipError pychip_Bdx_StopExpectingBdxTransfer() | ||
{ | ||
// TODO: Call BdxTransferManager::StopExpectingATransfer. | ||
} | ||
|
||
PyChipError pychip_Bdx_AcceptSendTransfer(void * transfer, PyObject dataReceivedContext, PyObject transferCompletedContext) | ||
{ | ||
// TODO: Pass transferCompletedContext to transfer so that the system will call gOnTransferCompletedCallback with | ||
// transferCompletedContext eventually. | ||
// TODO: Call transfer->AcceptSend with a data callback to call gOnDataReceivedCallback with dataReceivedContext. | ||
} | ||
|
||
PyChipError pychip_Bdx_AcceptReceiveTransfer(void * transfer, const uint8_t * dataBuffer, size_t dataLength, | ||
void * transferCompletedContext) | ||
{ | ||
// TODO: Pass transferCompletedContext to transfer so that the system will call gOnTransferCompletedCallback with | ||
// transferCompletedContext eventually. | ||
// TODO: Call transfer->AcceptReceive with the data. | ||
} | ||
|
||
PyChipError pychip_Bdx_RejectTransfer(void * transfer) | ||
{ | ||
// TODO: Pass transferCompletedContext to transfer so that the system will call gOnTransferCompletedCallback with | ||
// transferCompletedContext eventually. | ||
// TODO: Call transfer->Reject. | ||
} | ||
|
||
} |