mizucp: implement scan thread
[mizunara.git] / mizucp / main.h
1 /*
2  * Copyright 2021 Olaf Wintermann
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a 
5  * copy of this software and associated documentation files (the "Software"), 
6  * to deal in the Software without restriction, including without limitation 
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
8  * and/or sell copies of the Software, and to permit persons to whom the 
9  * Software is furnished to do so, subject to the following conditions:
10  * 
11  * The above copyright notice and this permission notice shall be included in 
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
20  * DEALINGS IN THE SOFTWARE.
21  */
22
23 #ifndef MAIN_H
24 #define MAIN_H
25
26 #include <stdlib.h>
27
28 #include <ucx/string.h>
29
30 #include <pthread.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #define MZCP_ENV_HOME "HOME"
37 #define MZCP_CFG_BASE ".config"
38 #define MZCP_CFG_DIR  ".config/mizunara"
39 #define MZCP_COPY_DIR "copy"
40     
41 #define CLIENT_MSG_BUFSIZE 512
42     
43 #define MAX_COPY_THREADS 32
44     
45 typedef char CPBool;
46
47 typedef struct SrcFile SrcFile;
48 typedef struct MZLock  MZLock;
49 typedef struct MZQueue MZQueue;
50
51 typedef struct {
52     char   *from;
53     char   *to;
54     size_t num_threads;
55     CPBool url;
56     CPBool pause;
57     CPBool printsocket;
58 } CPSettings;
59
60 struct MZLock {
61     pthread_mutex_t mutex;
62     pthread_cond_t cond;
63 };
64
65 struct SrcFile {
66     /*
67      * src file path relative to CPSettings.from
68      */
69     char *path;
70     
71     /*
72      * is the file a directory
73      */
74     CPBool isdir;
75     
76     /*
77      * file successfully copied
78      */
79     CPBool finished;
80     
81     /*
82      * processing this file depends on another file (directory)
83      */
84     SrcFile *depends_on;
85     
86     /*
87      * lock used for waiting, until this resource is successfully copied
88      */
89     MZLock *lock;
90 };
91
92 struct MZQueue {
93     SrcFile *file;
94     MZQueue *next;
95 };
96
97 const char* mzcp_get_cfgdir(void);
98 const char* mzcp_get_copydir(void);
99
100 int mzcp_copy(CPSettings *settings);
101
102 int mzcp_start_scan(CPSettings *settings);
103 void* scan_run(void *data);
104
105 int enqueue_file(SrcFile *file);
106
107 int mzcp_start_copy_threads(CPSettings *settings);
108 void* copy_run(void *data);
109
110
111     
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif /* MAIN_H */
117