libdoclone  0.8.0
clone.h
1 /*
2  * libdoclone - library for cloning GNU/Linux systems
3  * Copyright (C) 2013-2015 Joan Lledó <joanlluislledo@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _CLONE_H_
20 #define _CLONE_H_
21 
47 #include <stdint.h>
48 
49 /* Include this headers only in C++
50  *
51  * For C, libdoclone has another API defined bellow
52  */
53 #ifdef __cplusplus
54 
55 #include <doclone/DataTransfer.h>
56 #include <doclone/Logger.h>
57 #include <doclone/observer/AbstractObserver.h>
58 #include <doclone/Operation.h>
59 #include <doclone/exception/Exception.h>
60 
61 #endif //__cplusplus
62 
63 /*
64  * C Wrapper API
65  */
66 
248 #ifdef __cplusplus
249 extern "C" {
250 #endif
251 
261 typedef enum dcTransferEvent {
265 
275 typedef enum dcOperationEvent {
279 
313 typedef enum dcOperationType {
329 
341 typedef enum dcEvent {
345 } dcEvent;
346 
353 typedef void (*transferCallback) (dcTransferEvent event,
354  uint64_t numBytes);
355 
363  const char *target);
364 
370 typedef void (*generalCallback) (dcEvent event, const char *target);
371 
378 typedef void (*notificationCallback) (const char *str);
379 
384 typedef struct dc_doclone {
386  char _image[512];
388  char _device[512];
390  char _address[20];
392  char _interface[20];
394  uint32_t _nodesNumber;
396  uint8_t _empty;
398  uint8_t _force;
400  void * _observer;
401 } dc_doclone;
402 
403 
404 /*
405  * AC_CHECK_LIB Macro compatibility
406  */
408 
409 /*
410  * Memory management for the dc_doclone object
411  */
413 void doclone_destroy(dc_doclone *dc_obj);
414 
415 /*
416  * Operations that can be performed
417  */
418 int doclone_create(const dc_doclone *dc_obj);
419 int doclone_restore(const dc_doclone *dc_obj);
420 int doclone_send(const dc_doclone *dc_obj);
421 int doclone_receive(const dc_doclone *dc_obj);
422 int doclone_chain_origin(const dc_doclone *dc_obj);
423 int doclone_chain_link(const dc_doclone *dc_obj);
424 
425 /*
426  * Setters for the dc_doclone object
427  */
428 void doclone_set_image(dc_doclone *dc_obj, const char *image);
429 void doclone_set_device(dc_doclone *dc_obj, const char *device);
430 void doclone_set_address(dc_doclone *dc_obj, const char *address);
431 void doclone_set_interface(dc_doclone *dc_obj, const char *interface);
432 void doclone_set_nodes_number(dc_doclone *dc_obj, unsigned int number);
433 void doclone_set_empty(dc_doclone *dc_obj, unsigned short empty);
434 void doclone_set_force(dc_doclone *dc_obj, unsigned short force);
435 
436 /*
437  * Functions for set the callbacks of libdoclone events
438  */
440  transferCallback call);
442  operationCallback call);
444  generalCallback call);
446  notificationCallback call);
447 
450 #ifdef __cplusplus
451 }
452 #endif
453 
454 #ifdef __cplusplus
455 
462 class DefaultObserver : public Doclone::AbstractObserver {
463 public:
464  DefaultObserver();
465 
466  void notify(Doclone::dcTransferEvent event, uint64_t numBytes);
467  void notify(Doclone::dcOperationEvent event,
468  Doclone::dcOperationType type, const std::string &target);
469  void notify(Doclone::dcEvent event, const std::string &target);
470  void notify(const std::string &str);
471 
472  void setTCallback(const transferCallback call);
473  void setOCallback(const operationCallback call);
474  void setGCallback(const generalCallback call);
475  void setNCallback(const notificationCallback call);
476 
477 private:
479  transferCallback _tCallback;
481  operationCallback _oCallback;
483  generalCallback _gCallback;
485  notificationCallback _nCallback;
486 };
487 
488 #endif //__cplusplus
489 
490 #endif /* _CLONE_H_ */
char _address[20]
Ip address entered by the user.
Definition: clone.h:390
void doclone_set_empty(dc_doclone *dc_obj, unsigned short empty)
Sets the empty flag of the given dc_doclone object.
Definition: clone.cc:320
int doclone_chain_link(const dc_doclone *dc_obj)
Receives an image or a device from the network in link mode.
Definition: clone.cc:205
void * _observer
Event subscriber object.
Definition: clone.h:400
int doclone_receive(const dc_doclone *dc_obj)
Receives an image or a device from the network.
Definition: clone.cc:152
char _device[512]
Device path entered by the user.
Definition: clone.h:388
void doclone_set_address(dc_doclone *dc_obj, const char *address)
Sets the IP address of the server for the given dc_doclone object.
Definition: clone.cc:294
void doclone_subscribe_to_notifications(dc_doclone *dc_obj, notificationCallback call)
Through this function the user can set its callback for listen the notifications of the exceptions...
Definition: clone.cc:263
void doclone_set_force(dc_doclone *dc_obj, unsigned short force)
Sets the force flag of the given dc_doclone object.
Definition: clone.cc:328
void doclone_subscribe_to_operation_events(dc_doclone *dc_obj, operationCallback call)
Through this function the user can set its callback for the operation events of the library...
Definition: clone.cc:240
char _image[512]
Image path entered by the user.
Definition: clone.h:386
void(* operationCallback)(dcOperationEvent event, dcOperationType type, const char *target)
The prototype of the function to be called when an operation event has occurred.
Definition: clone.h:362
Reading the data of a partition.
Definition: clone.h:322
Writing a new disklabel.
Definition: clone.h:316
Writing the data of a partition.
Definition: clone.h:323
void doclone_subscribe_to_general_events(dc_doclone *dc_obj, generalCallback call)
Through this function the user can set its callback for the general events of the library...
Definition: clone.cc:251
Writing the label of a filesystem.
Definition: clone.h:320
int doclone_send(const dc_doclone *dc_obj)
Sends an image or a device to the network.
Definition: clone.cc:123
int doclone_chain_origin(const dc_doclone *dc_obj)
Sends an image or a device to the network in link mode.
Definition: clone.cc:179
int libdoclone_is_present()
For compatibility with AC_CHECK_LIB.
Definition: clone.cc:34
void doclone_destroy(dc_doclone *dc_obj)
Destroy the given dc_doclone object.
Definition: clone.cc:57
dcOperationType
C wrapper for Doclone::dcOperationType.
Definition: clone.h:313
dc_doclone * doclone_new()
Creates a new dc_doclone object in the heap and returns its address.
Definition: clone.cc:44
void doclone_subscribe_to_tranfer_events(dc_doclone *dc_obj, transferCallback call)
Through this function the user can set its callback for the transfer events of the library...
Definition: clone.cc:228
char _interface[20]
Ip address of the network interface entered by the user.
Definition: clone.h:392
The program detects a SIGINT.
Definition: clone.h:342
void(* generalCallback)(dcEvent event, const char *target)
The prototype of the function to be called when a general event has occurred.
Definition: clone.h:370
Creating a new partition.
Definition: clone.h:317
Formatting a partition.
Definition: clone.h:318
Sending or receiving data.
Definition: clone.h:325
Main object of the C wrapper API of libdoclone.
Definition: clone.h:384
Installing GRUB.
Definition: clone.h:324
uint8_t _empty
Empty mode enabled/disabled.
Definition: clone.h:396
Reading the partition table.
Definition: clone.h:315
Execution successfully finished.
Definition: clone.h:343
dcEvent
C wrapper for Doclone::dcEvent.
Definition: clone.h:341
void(* notificationCallback)(const char *str)
The prototype of the function to be called when an exception occurs and notifies its message...
Definition: clone.h:378
Waiting for connect to server.
Definition: clone.h:326
int doclone_create(const dc_doclone *dc_obj)
Creates an image of a device.
Definition: clone.cc:70
dcTransferEvent
C wrapper for Doclone::dcTransferEvent.
Definition: clone.h:261
The subject has completed an operation pending.
Definition: clone.h:277
New incoming connection.
Definition: clone.h:344
void(* transferCallback)(dcTransferEvent event, uint64_t numBytes)
The prototype of the function to be called when a transfer event has occurred.
Definition: clone.h:353
The value of the total size to be transferred has changed.
Definition: clone.h:262
void doclone_set_interface(dc_doclone *dc_obj, const char *interface)
Sets the IP address of the interface to be used in the link mode.
Definition: clone.cc:302
No operation.
Definition: clone.h:314
void doclone_set_device(dc_doclone *dc_obj, const char *device)
Sets the device path of the given dc_doclone object.
Definition: clone.cc:286
Waiting for connect to client/s.
Definition: clone.h:327
void doclone_set_image(dc_doclone *dc_obj, const char *image)
Sets the image path of the given dc_doclone object.
Definition: clone.cc:278
dcOperationEvent
C wrapper for Doclone::dcOperationEvent.
Definition: clone.h:275
Writing the flags of a partition.
Definition: clone.h:319
uint8_t _force
Mode force enabled/disabled.
Definition: clone.h:398
void doclone_set_nodes_number(dc_doclone *dc_obj, unsigned int number)
Sets the number of receivers of the given dc_doclone object.
Definition: clone.cc:312
uint32_t _nodesNumber
Number of receivers entered by the user.
Definition: clone.h:394
Writing the uuid of a filesystem.
Definition: clone.h:321
int doclone_restore(const dc_doclone *dc_obj)
Restores an image in a device.
Definition: clone.cc:96
The value of the transferred bytes has changed.
Definition: clone.h:263
The subject has added a new operation pending.
Definition: clone.h:276