~ehmry/nim_tox

a0e0200ed69bb8473eceef3ad5776066ce003b1b — Emery Hemingway 10 months ago fd12809
Toxcore: tidy the API
1 files changed, 18 insertions(+), 2 deletions(-)

M src/toxcore.nim
M src/toxcore.nim => src/toxcore.nim +18 -2
@@ 262,7 262,7 @@ type

  Tox* = ref object
    ## Tox instance.
    core: Core
    core*: Core
    selfConnectionStatus: CbSelfConnectionStatus
    friendName: CbFriendName
    friendStatusMessage: CbFriendStatusMessage


@@ 856,12 856,17 @@ callbackSetter friend_message:
      length: csize; user_data: pointer) {.cdecl.} =
    callThru(friend, ctoxString(message, length), kind)

proc hash(hash: ptr uint8; data: pointer; length: csize): bool {.ctoxProc.}

proc hash*(data: pointer; size: int): Hash =
  ## Generate cryptographic hash of the given data,
  ## provided primarily for validating cached avatars.
  proc hash(hash: ptr uint8; data: pointer; length: csize): bool {.ctoxProc.}
  discard hash(addr result.bytes[0], data, size)

proc hash*(data: string): Hash =
  ## Generate cryptographic hash of the given data.
  discard hash(addr result.bytes[0], unsafeAddr data[0], data.len)

type Err_File_Control {.ctoxEnum.} = enum
  TOX_ERR_FILE_CONTROL_OK,
  TOX_ERR_FILE_CONTROL_FRIEND_NOT_FOUND,


@@ 935,6 940,17 @@ type Err_File_Send {.ctoxEnum.} = enum
  TOX_ERR_FILE_SEND_NAME_TOO_LONG,
  TOX_ERR_FILE_SEND_TOO_MANY

proc send*(tox: Tox; friend: Friend; kind: uint32; size: BiggestInt; id : Hash;
    filename: string): FileTransfer {.tags: [IOEffect].} =
  proc file_send(
    core: Core; friend: Friend; kind: uint32;
    file_size: uint64; file_id: ptr uint8; filename: cstring;
    filename_length: csize; error: ptr Err_File_Send): FileTransfer {.ctoxProc.}
  var err: Err_File_Send
  result = tox.core.file_send(
    friend, kind, size.uint64, unsafeAddr id.bytes[0], filename, filename.len, addr err)
  ctoxAssert(TOX_ERR_FILE_SEND_OK, err)

proc send*(tox: Tox; friend: Friend; kind: uint32; size: BiggestInt;
    filename: string): FileTransfer {.tags: [IOEffect].} =
  proc file_send(