aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/e_fm/e_fm_main.c
blob: 3788199630290d846a339cbc9261772b3266c240 (plain) (blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif defined __GNUC__
# define alloca __builtin_alloca
#elif defined _AIX
# define alloca __alloca
#elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
#else
# include <stddef.h>
# ifdef  __cplusplus
extern "C"
# endif
void *alloca (size_t);
#endif

#ifdef __linux__
#include <features.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/param.h>
#include <utime.h>
#include <math.h>
#include <fnmatch.h>
#include <limits.h>
#include <ctype.h>
#include <time.h>
#include <dirent.h>
#include <pwd.h>
#include <glob.h>
#include <errno.h>
#include <signal.h>
#include <Ecore.h>
#include <Ecore_Ipc.h>
#include <Ecore_File.h>
#include <Eet.h>

#define E_TYPEDEFS
#include "e_config_data.h"
#include "e_fm_op.h"
#undef E_TYPEDEFS
#include "e_config_data.h"
#include "e_fm_op.h"

#include "e_fm_shared_device.h"
#ifdef HAVE_UDISKS_MOUNT
# include "e_fm_main_udisks.h"
# include "e_fm_main_udisks2.h"
#endif
#ifdef HAVE_EEZE_MOUNT
# include "e_fm_main_eeze.h"
#endif


/* if using udisks, functions will point to _e_fm_main_udisks_X
 * if using eeze, functions will point to _e_fm_main_eeze_X
 */

static Efm_Mode mode = EFM_MODE_USING_RASTER_MOUNT;

/* FIXME: things to add to the slave enlightenment_fm process and ipc to e:
 *
 * * reporting results of fop's (current status - what has been don, what failed etc.)
 * * dbus removable device monitoring (in e17 itself now via eldbus - move to enlightenment_fm and ipc removable device add/del and anything else)
 * * mount/umount of removable devices (to go along with removable device support - put it in here and message back mount success/failure and where it is now mounted - remove from e17 itself)
 *
 */

#ifndef EAPI
#define EAPI
#endif

#include "e_fm_main.h"
#include "e_fm_shared_types.h"
#include "e_fm_shared_codec.h"
#include "e_fm_ipc.h"

int efm_log_dom = -1;

static void
_e_fm_init(void)
{
# ifdef HAVE_UDISKS_MOUNT
   _e_fm_main_udisks2_init();
# else
#  ifdef HAVE_EEZE_MOUNT
   _e_fm_main_eeze_init();
   mode = EFM_MODE_USING_EEZE_MOUNT; /* this gets overridden if the others are available */
#  endif
# endif
}

static void
_e_fm_shutdown(void)
{
# ifdef HAVE_UDISKS_MOUNT
   _e_fm_main_udisks2_shutdown();
   _e_fm_main_udisks_shutdown();
# else
#  ifdef HAVE_EEZE_MOUNT
   _e_fm_main_eeze_shutdown();
#  endif
# endif
}

/* externally accessible functions */
int
main(int argc, char **argv)
{
   if (argc > 1)
     {
        printf(
        "This is an internal tool for Enlightenment.\n"
        "do not use it.\n"
        );
        exit(0);
     }

   eina_init();
   eet_init();
   ecore_app_no_system_modules();
   ecore_init();
   ecore_app_args_set(argc, (const char **)argv);

   ecore_file_init();
   ecore_ipc_init();
   _e_storage_volume_edd_init();
   if (!_e_fm_ipc_init()) return -1;
   efm_log_dom = eina_log_domain_register("efm", EINA_COLOR_GREEN);
   _e_fm_init();

   ecore_event_handler_add(ECORE_EXE_EVENT_DATA, _e_fm_ipc_slave_data_cb, NULL);
   ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, _e_fm_ipc_slave_error_cb, NULL);
   ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _e_fm_ipc_slave_del_cb, NULL);

   ecore_main_loop_begin();

   if (_e_fm_ipc_server)
     {
        ecore_ipc_server_del(_e_fm_ipc_server);
        _e_fm_ipc_server = NULL;
     }

   _e_fm_shutdown();
   _e_storage_volume_edd_shutdown();
   ecore_ipc_shutdown();
   ecore_file_shutdown();
   ecore_shutdown();
   eina_shutdown();
   return 0;
}

#ifdef HAVE_UDISKS_MOUNT
void
_e_fm_main_udisks_catch(Eina_Bool usable)
{
   if (usable)
     {
        mode = EFM_MODE_USING_UDISKS_MOUNT;
        return;
     }
# ifdef HAVE_EEZE_MOUNT
   _e_fm_main_eeze_init();
   mode = EFM_MODE_USING_EEZE_MOUNT;
# endif
}

void
_e_fm_main_udisks2_catch(Eina_Bool usable)
{
   if (usable)
     {
        mode = EFM_MODE_USING_UDISKS2_MOUNT;
        return;
     }
   _e_fm_main_udisks_init();
   mode = EFM_MODE_USING_UDISKS_MOUNT;
}
#endif

void
_e_storage_free(E_Storage *s)
{
   _e_fm_shared_device_storage_free(s);
}

void
_e_volume_free(E_Volume *v)
{
   _e_fm_shared_device_volume_free(v);
}

/* API functions */

EAPI void
e_volume_mount(E_Volume *v)
{
  switch (mode)
    {
#ifdef HAVE_UDISKS_MOUNT
     case EFM_MODE_USING_UDISKS_MOUNT:
       _e_fm_main_udisks_volume_mount(v);
       break;
     case EFM_MODE_USING_UDISKS2_MOUNT:
       _e_fm_main_udisks2_volume_mount(v);
       break;
#endif
#ifdef HAVE_EEZE_MOUNT
     case EFM_MODE_USING_EEZE_MOUNT:
       _e_fm_main_eeze_volume_mount(v);
       break;
#endif
     default:
       printf("raster can't mount disks by himself!\n");
       (void)v;
    }
}


EAPI void
e_volume_unmount(E_Volume *v)
{
  switch (mode)
    {
#ifdef HAVE_UDISKS_MOUNT
     case EFM_MODE_USING_UDISKS_MOUNT:
       _e_fm_main_udisks_volume_unmount(v);
       break;
     case EFM_MODE_USING_UDISKS2_MOUNT:
       _e_fm_main_udisks2_volume_unmount(v);
       break;
#endif
#ifdef HAVE_EEZE_MOUNT
     case EFM_MODE_USING_EEZE_MOUNT:
       _e_fm_main_eeze_volume_unmount(v);
       break;
#endif
     default:
       printf("raster can't unmount disks by himself!\n");
       (void)v;
    }
}

EAPI void
e_volume_eject(E_Volume *v)
{
  switch (mode)
    {
#ifdef HAVE_UDISKS_MOUNT
     case EFM_MODE_USING_UDISKS_MOUNT:
       _e_fm_main_udisks_volume_eject(v);
       break;
     case EFM_MODE_USING_UDISKS2_MOUNT:
       _e_fm_main_udisks2_volume_eject(v);
       break;
#endif
#ifdef HAVE_EEZE_MOUNT
     case EFM_MODE_USING_EEZE_MOUNT:
       _e_fm_main_eeze_volume_eject(v);
       break;
#endif
     default:
       printf("raster can't eject disks by himself!\n");
       (void)v;
    }
}

EAPI E_Volume *
e_volume_find(const char *udi)
{
   switch (mode)
     {
#ifdef HAVE_UDISKS_MOUNT
      case EFM_MODE_USING_UDISKS_MOUNT:
        return _e_fm_main_udisks_volume_find(udi);
      case EFM_MODE_USING_UDISKS2_MOUNT:
        return _e_fm_main_udisks2_volume_find(udi);
#endif
#ifdef HAVE_EEZE_MOUNT
      case EFM_MODE_USING_EEZE_MOUNT:
        return _e_fm_main_eeze_volume_find(udi);
#endif
      default:
        printf("raster can't find disks by himself!\n");
        (void)udi;
     }
   return NULL;
}

EAPI void
e_storage_del(const char *udi)
{
  switch (mode)
    {
#ifdef HAVE_UDISKS_MOUNT
     case EFM_MODE_USING_UDISKS_MOUNT:
       _e_fm_main_udisks_storage_del(udi);
       break;
     case EFM_MODE_USING_UDISKS2_MOUNT:
       _e_fm_main_udisks2_storage_del(udi);
       break;
#endif
#ifdef HAVE_EEZE_MOUNT
     case EFM_MODE_USING_EEZE_MOUNT:
       _e_fm_main_eeze_storage_del(udi);
       break;
#endif
     default:
       printf("raster can't delete disks by himself!\n");
       (void)udi;
    }
}

EAPI E_Storage *
e_storage_find(const char *udi)
{
  switch (mode)
    {
#ifdef HAVE_UDISKS_MOUNT
     case EFM_MODE_USING_UDISKS_MOUNT:
       return _e_fm_main_udisks_storage_find(udi);
     case EFM_MODE_USING_UDISKS2_MOUNT:
       return _e_fm_main_udisks2_storage_find(udi);
#endif
#ifdef HAVE_EEZE_MOUNT
     case EFM_MODE_USING_EEZE_MOUNT:
       return _e_fm_main_eeze_storage_find(udi);
#endif
     default:
       printf("raster can't find disks by himself!\n");
       (void)udi;
    }
  return NULL;
}