Valkka  0.17.0
OpenSource Video Management
tools.h
Go to the documentation of this file.
1 #ifndef TOOLS_HEADER_GUARD
2 #define TOOLS_HEADER_GUARD
3 
4 /*
5  * tools.h : Auxiliary routines
6  *
7  * Copyright 2017, 2018 Valkka Security Ltd. and Sampsa Riikonen.
8  *
9  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
10  *
11  * This file is part of the Valkka library.
12  *
13  * Valkka is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU Affero General Public License as
15  * published by the Free Software Foundation, either version 3 of the
16  * License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Affero General Public License for more details.
22  *
23  * You should have received a copy of the GNU Affero General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>
25  *
26  */
27 
39 #include "common.h"
40 #include "constant.h"
41 #include "logging.h"
42 
53 static const int64_t NANOSEC_PER_SEC = 1000000000;
54 
55 long int getCurrentMsTimestamp();
56 
57 long int getMsDiff(timeval tv1, timeval tv2);
58 
59 struct timeval msToTimeval(long int mstimestamp);
60 
61 long int timevalToMs(struct timeval time);
62 
63 bool slotOk(SlotNumber n_slot);
64 
65 void normalize_timespec(struct timespec *ts, time_t sec, int64_t nanosec);
66 
67 
68 #ifdef BIG_ENDIAN
69 uint32_t deserialize_uint32_big_endian(unsigned char *buffer)
70 {
71  uint32_t value = 0;
72 
73  value |= buffer[0] << 24;
74  value |= buffer[1] << 16;
75  value |= buffer[2] << 8;
76  value |= buffer[3];
77  return value;
78 }
79 #else // either not defined or little endian
80 // deserialize value from big endian in little endian system
81 // byte1 byte2 byte3 byte4 => byte4 byte3 ..
82 uint32_t deserialize_uint32_big_endian(unsigned char *buffer)
83 {
84  uint32_t value = 0;
85 
86  value |= buffer[3] << 24;
87  value |= buffer[2] << 16;
88  value |= buffer[1] << 8;
89  value |= buffer[0];
90  return value;
91 }
92 #endif
93 
94 
95 #endif
bool slotOk(SlotNumber n_slot)
Timeval to milliseconds.
Definition: tools.cpp:64
Constant/default values, version numbers.
Logging utilities.
struct timeval msToTimeval(long int mstimestamp)
Milliseconds to timeval.
Definition: tools.cpp:52
long int getMsDiff(timeval tv1, timeval tv2)
Utility function: return timedif of two timeval structs in milliseconds.
Definition: tools.cpp:47
List of common header files.
long int getCurrentMsTimestamp()
Utility function: returns current unix epoch timestamp in milliseconds. Uses timeval.
Definition: tools.cpp:40