-
Notifications
You must be signed in to change notification settings - Fork 84
/
std_commands.c
176 lines (163 loc) · 7.93 KB
/
std_commands.c
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
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "std_commands.h"
#include <stdlib.h>
#include <string.h>
#include "celix_constants.h"
#include "celix_shell_command.h"
#define NUMBER_OF_COMMANDS 13
struct celix_shell_command_register_entry {
bool (*exec)(void *handle, const char *commandLine, FILE *out, FILE *err);
char *name;
char *description;
char *usage;
celix_shell_command_t service;
celix_properties_t *props;
long svcId; //used for service (un)registration
};
struct celix_std_commands {
celix_bundle_context_t* ctx;
struct celix_shell_command_register_entry std_commands[NUMBER_OF_COMMANDS];
};
celix_std_commands_t* celix_stdCommands_create(celix_bundle_context_t* ctx) {
celix_std_commands_t* commands = calloc(1, sizeof(*commands));
commands->ctx = ctx;
commands->std_commands[0] =
(struct celix_shell_command_register_entry) {
.exec = lbCommand_execute,
.name = "celix::lb",
.description = "list bundles. Default all bundles are listed." \
"\nIf a group string is provided only bundles where the bundle group matching group string will be listed." \
"\nUse -l to print the bundle locations.\nUse -s to print the bundle symbolic names.\n",
.usage = "lb [-l | -s] [group]"
};
commands->std_commands[1] =
(struct celix_shell_command_register_entry) {
.exec = startCommand_execute,
.name = "celix::start",
.description = "start bundle(s).",
.usage = "start <id> [<id> ...]"
};
commands->std_commands[2] =
(struct celix_shell_command_register_entry) {
.exec = stopCommand_execute,
.name = "celix::stop",
.description = "stop bundle(s).",
.usage = "stop <id> [<id> ...]"
};
commands->std_commands[3] =
(struct celix_shell_command_register_entry) {
.exec = installCommand_execute,
.name = "celix::install",
.description = "install bundle(s).",
.usage = "install <file> [<file> ...]"
};
commands->std_commands[4] =
(struct celix_shell_command_register_entry) {
.exec = uninstallCommand_execute,
.name = "celix::uninstall",
.description = "uninstall bundle(s).",
.usage = "uninstall <id> [<id> ...]"
};
commands->std_commands[5] =
(struct celix_shell_command_register_entry) {
.exec = updateCommand_execute,
.name = "celix::update",
.description = "update bundle(s).",
.usage = "update <id> [<URL>]"
};
commands->std_commands[6] =
(struct celix_shell_command_register_entry) {
.exec = helpCommand_execute,
.name = "celix::help",
.description = "display available commands or detail info if a command argument is provided",
.usage = "help [<command>]"
};
commands->std_commands[7] =
(struct celix_shell_command_register_entry) {
.exec = dmListCommand_execute,
.name = "celix::dm",
.description = "Gives an overview of the component managed by a dependency manager.",
.usage = "dm [wtf] [f|full] [<Bundle ID> [<Bundle ID> [...]]]"
};
commands->std_commands[8] =
(struct celix_shell_command_register_entry) {
.exec = queryCommand_execute,
.name = "celix::query",
.description = "Query services. Query for registered and requested services" \
"\nIf a query is provided (or multiple), only service with a service name matching the query will be displayed." \
"\nIf a query is a (LDAP) filter, filter matching will be used."
"\nIf no query is provided all provided and requested services will be listed."
"\n\tIf the -v option is provided, also list the service properties." \
"\n\tIf the -r option is provided, only query for requested services." \
"\n\tIf the -p option is provided, only query for provided services.",
.usage = "query [bundleId ...] [-v] [-p] [-r] [query ...]"
};
commands->std_commands[9] =
(struct celix_shell_command_register_entry) {
.exec = queryCommand_execute,
.name = "celix::q",
.description = "Proxy for query command (see 'help query')",
.usage = "q [bundleId ...] [-v] [-p] [-r] [query ...]"
};
commands->std_commands[10] =
(struct celix_shell_command_register_entry) {
.exec = quitCommand_execute,
.name = "celix::quit",
.description = "Quit (exit) framework.",
.usage = "quit"
};
commands->std_commands[11] =
(struct celix_shell_command_register_entry) {
.exec = unloadCommand_execute,
.name = "celix::unload",
.description = "unload bundle(s).",
.usage = "unload <id> [<id> ...]"
};
commands->std_commands[12] =
(struct celix_shell_command_register_entry) {
.exec = NULL
};
for (unsigned int i = 0; commands->std_commands[i].exec != NULL; ++i) {
commands->std_commands[i].props = celix_properties_create();
celix_properties_set(commands->std_commands[i].props, CELIX_SHELL_COMMAND_NAME, commands->std_commands[i].name);
celix_properties_set(commands->std_commands[i].props, CELIX_SHELL_COMMAND_USAGE, commands->std_commands[i].usage);
celix_properties_set(commands->std_commands[i].props, CELIX_SHELL_COMMAND_DESCRIPTION, commands->std_commands[i].description);
commands->std_commands[i].service.handle = ctx;
commands->std_commands[i].service.executeCommand = commands->std_commands[i].exec;
celix_service_registration_options_t opts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
opts.svc = &commands->std_commands[i].service;
opts.serviceName = CELIX_SHELL_COMMAND_SERVICE_NAME;
opts.serviceVersion = CELIX_SHELL_COMMAND_SERVICE_VERSION;
opts.properties = commands->std_commands[i].props;
commands->std_commands[i].svcId = celix_bundleContext_registerServiceWithOptions(ctx, &opts);
}
return commands;
}
void celix_stdCommands_destroy(celix_std_commands_t* commands) {
if (commands != NULL) {
for (unsigned int i = 0; commands->std_commands[i].exec != NULL; i++) {
if (commands->std_commands[i].svcId >= 0) {
celix_bundleContext_unregisterService(commands->ctx, commands->std_commands[i].svcId);
commands->std_commands[i].props = NULL;
}
}
}
free(commands);
}