Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | #ifndef UTIL_H |
| 8 | #define UTIL_H |
| 9 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <stdarg.h> |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 13 | #include <stdint.h> |
David Sodman | e46ea8a | 2015-03-13 15:47:12 -0700 | [diff] [blame] | 14 | #include <stdbool.h> |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 15 | #include <time.h> |
| 16 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 17 | #define MAX(A, B) ((A) > (B) ? (A) : (B)) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 18 | #define MIN(A, B) ((A) < (B) ? (A) : (B)) |
| 19 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 20 | #define ARRAY_SIZE(A) (sizeof(A)/sizeof(*(A))) |
| 21 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 22 | #define MS_PER_SEC (1000LL) |
| 23 | #define NS_PER_SEC (1000LL * 1000LL * 1000LL) |
| 24 | #define NS_PER_MS (NS_PER_SEC / MS_PER_SEC); |
| 25 | |
| 26 | /* Returns the current CLOCK_MONOTONIC time in milliseconds. */ |
| 27 | inline int64_t get_monotonic_time_ms() { |
| 28 | struct timespec spec; |
| 29 | clock_gettime(CLOCK_MONOTONIC, &spec); |
| 30 | return MS_PER_SEC * spec.tv_sec + spec.tv_nsec / NS_PER_MS; |
| 31 | } |
| 32 | |
| 33 | void LOG(int severity, const char* fmt, ...); |
| 34 | void daemonize(); |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 35 | void parse_location(char* loc_str, int* x, int* y); |
| 36 | void parse_filespec(char* filespec, char* filename, |
| 37 | int32_t* offset_x, int32_t* offset_y, uint32_t* duration, |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 38 | uint32_t default_duration, int32_t default_x, int32_t default_y); |
| 39 | void parse_image_option(char* optionstr, char** name, char** val); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 40 | |
| 41 | |
| 42 | #define ERROR (1) |
| 43 | #define WARNING (2) |
| 44 | #define INFO (4) |
| 45 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 46 | #endif |