This commit is contained in:
Green Sky 2023-04-10 00:37:40 +02:00
parent bb19e742b5
commit 4b60192769
No known key found for this signature in database
3 changed files with 56 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "./tox_default_impl.hpp"
#include <optional>
Tox_Connection ToxDefaultImpl::toxSelfGetConnectionStatus(void) {
return tox_self_get_connection_status(_tox);
@ -113,6 +114,46 @@ std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Send_Message> ToxDefaultImpl:
}
}
Tox_Err_File_Control ToxDefaultImpl::toxFileControl(uint32_t friend_number, uint32_t file_number, Tox_File_Control control) {
Tox_Err_File_Control err = TOX_ERR_FILE_CONTROL_OK;
tox_file_control(_tox, friend_number, file_number, control, &err);
return err;
}
Tox_Err_File_Seek ToxDefaultImpl::toxFileSeek(uint32_t friend_number, uint32_t file_number, uint64_t position) {
Tox_Err_File_Seek err = TOX_ERR_FILE_SEEK_OK;
tox_file_seek(_tox, friend_number, file_number, position, &err);
return err;
}
std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_File_Get> ToxDefaultImpl::toxFileGetFileID(uint32_t friend_number, uint32_t file_number) {
Tox_Err_File_Get err = TOX_ERR_FILE_GET_OK;
std::vector<uint8_t> id(TOX_FILE_ID_LENGTH);
tox_file_get_file_id(_tox, friend_number, file_number, id.data(), &err);
if (err == TOX_ERR_FILE_GET_OK) {
return {id, err};
} else {
return {std::nullopt, err};
}
}
std::tuple<std::optional<uint32_t>, Tox_Err_File_Send> ToxDefaultImpl::toxFileSend(uint32_t friend_number, uint32_t kind, uint64_t file_size, const std::vector<uint8_t>& file_id, std::string_view filename) {
// TODO: check file_id size
Tox_Err_File_Send err = TOX_ERR_FILE_SEND_OK;
auto res = tox_file_send(_tox, friend_number, kind, file_size, file_id.data(), reinterpret_cast<const uint8_t*>(filename.data()), filename.size(), &err);
if (err == TOX_ERR_FILE_SEND_OK) {
return {res, err};
} else {
return {std::nullopt, err};
}
}
Tox_Err_File_Send_Chunk ToxDefaultImpl::toxFileSendChunk(uint32_t friend_number, uint32_t file_number, uint64_t position, const std::vector<uint8_t>& data) {
Tox_Err_File_Send_Chunk err = TOX_ERR_FILE_SEND_CHUNK_OK;
tox_file_send_chunk(_tox, friend_number, file_number, position, data.data(), data.size(), &err);
return err;
}
std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Join> ToxDefaultImpl::toxConferenceJoin(uint32_t friend_number, const std::vector<uint8_t>& cookie) {
Tox_Err_Conference_Join err = TOX_ERR_CONFERENCE_JOIN_OK;
auto res = tox_conference_join(_tox, friend_number, cookie.data(), cookie.size(), &err);

View File

@ -35,6 +35,12 @@ struct ToxDefaultImpl : public ToxI {
std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Send_Message> toxFriendSendMessage(uint32_t friend_number, Tox_Message_Type type, std::string_view message) override;
// files
Tox_Err_File_Control toxFileControl(uint32_t friend_number, uint32_t file_number, Tox_File_Control control) override;
Tox_Err_File_Seek toxFileSeek(uint32_t friend_number, uint32_t file_number, uint64_t position) override;
std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_File_Get> toxFileGetFileID(uint32_t friend_number, uint32_t file_number) override;
std::tuple<std::optional<uint32_t>, Tox_Err_File_Send> toxFileSend(uint32_t friend_number, uint32_t kind, uint64_t file_size, const std::vector<uint8_t>& file_id, std::string_view filename) override;
Tox_Err_File_Send_Chunk toxFileSendChunk(uint32_t friend_number, uint32_t file_number, uint64_t position, const std::vector<uint8_t>& data) override;
// conferece
std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Join> toxConferenceJoin(uint32_t friend_number, const std::vector<uint8_t>& cookie) override;
Tox_Err_Conference_Send_Message toxConferenceSendMessage(uint32_t conference_number, Tox_Message_Type type, std::string_view message) override;

View File

@ -48,6 +48,11 @@ struct ToxI_raw {
virtual std::vector<uint8_t> toxHash(const std::vector<uint8_t>& data);
// files
virtual Tox_Err_File_Control toxFileControl(uint32_t friend_number, uint32_t file_number, Tox_File_Control control) = 0;
virtual Tox_Err_File_Seek toxFileSeek(uint32_t friend_number, uint32_t file_number, uint64_t position) = 0;
virtual std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_File_Get> toxFileGetFileID(uint32_t friend_number, uint32_t file_number) = 0;
virtual std::tuple<std::optional<uint32_t>, Tox_Err_File_Send> toxFileSend(uint32_t friend_number, uint32_t kind, uint64_t file_size, const std::vector<uint8_t>& file_id, std::string_view filename) = 0;
virtual Tox_Err_File_Send_Chunk toxFileSendChunk(uint32_t friend_number, uint32_t file_number, uint64_t position, const std::vector<uint8_t>& data) = 0;
// conferece
//bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error);
@ -160,6 +165,10 @@ struct ToxI : public ToxI_raw {
return toxFriendSendMessage(friend_number, type, message);
}
std::tuple<std::optional<uint32_t>, Tox_Err_File_Send> toxFileSend_str(uint32_t friend_number, uint32_t kind, uint64_t file_size, const std::vector<uint8_t>& file_id, const std::string& filename) {
return toxFileSend(friend_number, kind, file_size, file_id, filename);
}
Tox_Err_Conference_Send_Message toxConferenceSendMessage_str(uint32_t conference_number, Tox_Message_Type type, const std::string& message) {
return toxConferenceSendMessage(conference_number, type, message);
}