2011-05-13 12:07:28 +04:00
/*
* Copyright ( C ) 2011 Red Hat , Inc . All rights reserved .
*
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v .2 .1 .
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
2011-07-18 18:46:54 +04:00
# include "libdevmapper.h" // for dm_list, needed by config.h
2011-06-14 06:34:18 +04:00
2011-05-13 12:07:28 +04:00
# ifndef _LVM_DAEMON_COMMON_CLIENT_H
# define _LVM_DAEMON_COMMON_CLIENT_H
typedef struct {
int socket_fd ; /* the fd we use to talk to the daemon */
int protocol ; /* version of the protocol the daemon uses */
} daemon_handle ;
typedef struct {
const char * path ; /* the binary of the daemon */
const char * socket ; /* path to the comms socket */
unsigned autostart : 1 ; /* start the daemon if not running? */
} daemon_info ;
typedef struct {
2011-06-14 06:34:18 +04:00
char * buffer ;
2011-06-27 16:26:54 +04:00
/*
* The request looks like this :
* request = " id "
* arg_foo = " something "
* arg_bar = 3
* arg_wibble {
* something_special = " here "
* amount = 75
* knobs = [ " twiddle " , " tweak " ]
* }
*/
2011-08-30 19:42:56 +04:00
struct dm_config_tree * cft ;
2011-05-13 12:07:28 +04:00
} daemon_request ;
typedef struct {
2011-05-15 15:02:29 +04:00
int error ; /* 0 for success */
2011-06-14 06:34:18 +04:00
char * buffer ; /* textual reply */
2011-08-30 19:42:56 +04:00
struct dm_config_tree * cft ; /* parsed reply, if available */
2011-05-13 12:07:28 +04:00
} daemon_reply ;
/*
* Open the communication channel to the daemon . If the daemon is not running ,
* it may be autostarted based on the binary path provided in the info ( this
* will only happen if autostart is set to true ) . If the call fails for any
* reason , daemon_handle_valid ( h ) for the response will return false . Otherwise ,
* the connection is good to start serving requests .
*/
daemon_handle daemon_open ( daemon_info i ) ;
/*
* Send a request to the daemon , waiting for the reply . All communication with
* the daemon is synchronous . The function handles the IO details and parses the
* response , handling common error conditions . See " daemon_reply " for details .
2011-06-27 16:26:54 +04:00
*
* In case the request contains a non - NULL buffer pointer , this buffer is sent
* * verbatim * to the server . In this case , the cft pointer may be NULL ( but will
* be ignored even if non - NULL ) . If the buffer is NULL , the cft is required to
* be a valid pointer , and is used to build up the request .
2011-05-13 12:07:28 +04:00
*/
2011-05-15 15:02:29 +04:00
daemon_reply daemon_send ( daemon_handle h , daemon_request r ) ;
2011-05-13 12:07:28 +04:00
2011-06-27 16:26:54 +04:00
/*
* A simple interface to daemon_send . This function just takes the command id
* and possibly a list of parameters ( of the form " name = %? " , " value " ) . The
* type ( string , integer ) of the value is indicated by a character substituted
* for ? in % ? : d for integer , s for string .
*/
2012-01-15 19:16:50 +04:00
daemon_reply daemon_send_simple ( daemon_handle h , const char * id , . . . ) ;
2011-06-27 16:26:54 +04:00
2011-06-27 17:58:11 +04:00
void daemon_reply_destroy ( daemon_reply r ) ;
2011-06-27 18:03:58 +04:00
static inline int daemon_reply_int ( daemon_reply r , const char * path , int def ) {
2011-08-30 19:42:56 +04:00
return dm_config_find_int ( r . cft - > root , path , def ) ;
2011-06-27 18:03:58 +04:00
}
static inline const char * daemon_reply_str ( daemon_reply r , const char * path , const char * def ) {
2011-08-30 19:42:56 +04:00
return dm_config_find_str ( r . cft - > root , path , def ) ;
2011-06-27 18:03:58 +04:00
}
2011-05-13 12:07:28 +04:00
/* Shut down the communication to the daemon. Compulsory. */
void daemon_close ( daemon_handle h ) ;
# endif