wimax-tools  1.4.4
cmd.h
Go to the documentation of this file.
1 /*
2  * Linux WiMax
3  * Swiss-army WiMAX knife header file
4  *
5  *
6  * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7  * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  * * Neither the name of Intel Corporation nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  * This is the common interface for plugins to implement support for
36  * the 'wimaxll' command line tool.
37  */
38 #ifndef __wimaxll__cmd_h__
39 #define __wimaxll__cmd_h__
40 
41 #define _GNU_SOURCE
42 #include <stdlib.h>
43 #include <string.h>
44 #include <error.h>
45 #include <net/if.h>
46 #include <errno.h>
47 #include <argp.h>
48 #include <wimaxll.h>
49 
50 struct wimax_handle;
51 
52 /* A plugin definition and declaration */
53 struct plugin {
54  const char *name;
55  const char *version;
56  int (*init)(void);
57  void (*exit)(void);
58  void *dl_handle;
59  int active;
60 };
61 
62 #define PLUGIN(_name, _version, _init, _exit) \
63 struct plugin plugin = { \
64  .name = _name, \
65  .version = _version, \
66  .init = _init, \
67  .exit = _exit, \
68 };
69 
70 /* Definining support for a command */
71 struct cmd {
72  char *name;
73  struct argp argp;
74  int (*fn)(struct cmd *, struct wimaxll_handle *,
75  int argc, char **argv);
76 };
77 
78 int w_cmd_register(struct cmd *);
79 void w_cmd_unregister(struct cmd *);
80 
81 /* Misc utilities */
82 void w_cmd_need_if(struct wimaxll_handle *);
83 void w_abort(int result, const char *fmt, ...)
84  __attribute__ ((format(printf, 2, 3)));
85 void w_msg(unsigned, const char *, unsigned, const char *fmt, ...)
86  __attribute__ ((format(printf, 4, 5)));
87 
88 /* Logging / printing */
89 enum {
97 };
98 
99 #define w_error(fmt...) w_msg(W_ERROR, __FILE__, __LINE__, "E: " fmt)
100 #define w_warn(fmt...) w_msg(W_WARN, __FILE__, __LINE__, "W: " fmt)
101 #define w_info(fmt...) w_msg(W_INFO, __FILE__, __LINE__, "I: " fmt)
102 #define w_print(fmt...) w_msg(W_PRINT, __FILE__, __LINE__, fmt)
103 #define w_d1(fmt...) w_msg(W_D1, __FILE__, __LINE__, "D1: " fmt)
104 #define w_d2(fmt...) w_msg(W_D2, __FILE__, __LINE__, "D2: " fmt)
105 #define w_d3(fmt...) w_msg(W_D3, __FILE__, __LINE__, "D3: " fmt)
106 
107 #endif /* #define __wimaxll__cmd_h__ */
const char * name
Definition: cmd.h:54
A WiMax control pipe handle.
Definition: internal.h:219
void w_cmd_need_if(struct wimaxll_handle *wmx)
Definition: wimaxll.c:126
Definition: cmd.h:71
const char * version
Definition: cmd.h:55
void w_msg(unsigned level, const char *file, unsigned line, const char *fmt,...)
Definition: wimaxll.c:79
char * name
Definition: cmd.h:72
Definition: cmd.h:53
int(* fn)(struct cmd *, struct wimaxll_handle *, int argc, char **argv)
Definition: cmd.h:74
Definition: cmd.h:90
void w_abort(int result, const char *fmt,...)
Definition: wimaxll.c:101
struct argp argp
Definition: cmd.h:73
Definition: cmd.h:93
int active
Definition: cmd.h:59
Definition: cmd.h:94
void * dl_handle
Definition: cmd.h:58
Definition: cmd.h:96
Definition: cmd.h:92
Definition: cmd.h:91
Definition: cmd.h:95
int(* init)(void)
Definition: cmd.h:56
void(* exit)(void)
Definition: cmd.h:57
void w_cmd_unregister(struct cmd *cmd)
Definition: wimaxll.c:121
int w_cmd_register(struct cmd *cmd)
Definition: wimaxll.c:115