wimax-tools 1.4.4

/home/users/builder/rpm/BUILD/wimax-tools-1.4.4/include/wimaxll/cmd.h

Go to the documentation of this file.
00001 /*
00002  * Linux WiMax
00003  * Swiss-army WiMAX knife header file
00004  *
00005  *
00006  * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
00007  * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above copyright
00016  *     notice, this list of conditions and the following disclaimer in
00017  *     the documentation and/or other materials provided with the
00018  *     distribution.
00019  *   * Neither the name of Intel Corporation nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  * This is the common interface for plugins to implement support for
00036  * the 'wimaxll' command line tool. 
00037  */
00038 #ifndef __wimaxll__cmd_h__
00039 #define __wimaxll__cmd_h__
00040 
00041 #define _GNU_SOURCE
00042 #include <stdlib.h>
00043 #include <string.h>
00044 #include <error.h>
00045 #include <net/if.h>
00046 #include <errno.h>
00047 #include <argp.h>
00048 #include <wimaxll.h>
00049 
00050 struct wimax_handle;
00051 
00052 /* A plugin definition and declaration */
00053 struct plugin {
00054         const char *name;
00055         const char *version;
00056         int (*init)(void);
00057         void (*exit)(void);
00058         void *dl_handle;
00059         int active;
00060 };
00061 
00062 #define PLUGIN(_name, _version, _init, _exit)           \
00063 struct plugin plugin = {                                \
00064         .name = _name,                                  \
00065         .version = _version,                            \
00066         .init = _init,                                  \
00067         .exit = _exit,                                  \
00068 };
00069 
00070 /* Definining support for a command */
00071 struct cmd {
00072         char *name;
00073         struct argp argp;
00074         int (*fn)(struct cmd *, struct wimaxll_handle *,
00075                   int argc, char **argv);
00076 };
00077 
00078 int w_cmd_register(struct cmd *);
00079 void w_cmd_unregister(struct cmd *);
00080 
00081 /* Misc utilities */
00082 void w_cmd_need_if(struct wimaxll_handle *);
00083 void w_abort(int result, const char *fmt, ...)
00084         __attribute__ ((format(printf, 2, 3)));
00085 void w_msg(unsigned, const char *, unsigned, const char *fmt, ...)
00086         __attribute__ ((format(printf, 4, 5)));
00087 
00088 /* Logging / printing */
00089 enum {
00090         W_ERROR,
00091         W_WARN,
00092         W_INFO,
00093         W_PRINT,
00094         W_D1,
00095         W_D2,
00096         W_D3,
00097 };
00098 
00099 #define w_error(fmt...) w_msg(W_ERROR, __FILE__, __LINE__, "E: " fmt)
00100 #define w_warn(fmt...) w_msg(W_WARN, __FILE__, __LINE__, "W: " fmt)
00101 #define w_info(fmt...) w_msg(W_INFO, __FILE__, __LINE__, "I: " fmt)
00102 #define w_print(fmt...) w_msg(W_PRINT, __FILE__, __LINE__, fmt)
00103 #define w_d1(fmt...) w_msg(W_D1, __FILE__, __LINE__, "D1: " fmt)
00104 #define w_d2(fmt...) w_msg(W_D2, __FILE__, __LINE__, "D2: " fmt)
00105 #define w_d3(fmt...) w_msg(W_D3, __FILE__, __LINE__, "D3: " fmt)
00106 
00107 #endif /* #define __wimaxll__cmd_h__ */