summaryrefslogtreecommitdiff
path: root/toxrtp/toxrtp_helper.h
blob: c9bcfccadd122516697b6d0ec6d004a6b4c62571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* rtp_helper.h
*
* Has some standard functions. !Red!
*
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
*
* Tox is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef _RTP__HELPER_H_
#define _RTP__HELPER_H_

#include <time.h>
#include <inttypes.h>

/* Current time, unix format */
/*#define _time ((uint32_t)time(NULL))*/

#define SUCCESS 0
#define FAILURE -1

#define _USE_ERRORS

#define RUN_IN_THREAD(_func, _thread_id, _arg_ptr) \
if ( pthread_create ( &_thread_id, NULL, _func, _arg_ptr ) ) { \
    pthread_detach ( _thread_id ); \
}

/* Core adaptation helper */
int t_setipport ( const char* _ip, unsigned short _port, void* _cont );
uint32_t t_random ( uint32_t _max );

/* It's a bit faster than the memcpy it self and more optimized for using
 * a uint8_t since memcpy has optimizations when copying "words" i.e. long type.
 * Otherwise it just copies char's while we need only uint8_t
 */
void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size );


/* This is our memset. It's also a bit faster than the memset for it
 * does not cast _dest to char* and uses faster loop algorithm.
 */
uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size );

/* Get null terminated len */
size_t t_memlen ( const uint8_t* _valu );

/* finds location of substring */
size_t t_strfind ( const uint8_t* _str, const uint8_t* _substr );

/* string alloc and copy ( ! must be null terminated ) */
uint8_t* t_strallcpy ( const uint8_t* _source );

/* Get current time in milliseconds */
uint64_t t_time();


#endif /* _RTP__HELPER_H_ */