mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-16 18:03:23 +00:00
system/nxinit: Add setprop support for action
Add the property backend and a setprop builtin so that setting a property can feed action triggers. property_simple.c provides a minimal init_property_*() implementation whose init_property_set() forwards the key/value pair to init_action_trigger_event(), and init.c wires the property poller into the init poll loop. Signed-off-by: fangpeina <fangpeina@xiaomi.com> Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
parent
2ca518bad7
commit
d04cffd986
8 changed files with 161 additions and 27 deletions
|
|
@ -24,6 +24,8 @@ if(CONFIG_SYSTEM_NXINIT)
|
|||
|
||||
set(CSRCS init.c action.c builtin.c import.c parser.c service.c)
|
||||
|
||||
list(APPEND CSRCS property_simple.c)
|
||||
|
||||
nuttx_add_application(
|
||||
MODULE
|
||||
${CONFIG_SYSTEM_NXINIT}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ CSRCS += parser.c
|
|||
CSRCS += action.c
|
||||
CSRCS += service.c
|
||||
CSRCS += import.c
|
||||
CSRCS += property_simple.c
|
||||
|
||||
PROGNAME = $(CONFIG_SYSTEM_NXINIT_PROGNAME)
|
||||
PRIORITY = $(CONFIG_SYSTEM_NXINIT_PRIORITY)
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ struct action_manager_s
|
|||
struct timespec time_run;
|
||||
#endif
|
||||
FAR struct service_manager_s *sm;
|
||||
|
||||
FAR struct init_poller_s *prop;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "builtin.h"
|
||||
#include "init.h"
|
||||
#include "property.h"
|
||||
#include "service.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -59,6 +60,10 @@ static int cmd_start(FAR struct action_manager_s *am,
|
|||
int argc, FAR char **argv);
|
||||
static int cmd_stop(FAR struct action_manager_s *am,
|
||||
int argc, FAR char **argv);
|
||||
#if CONFIG_SYSTEM_NXINIT_ACTION_EVENTS_MAX > 1
|
||||
static int cmd_setprop(FAR struct action_manager_s *am,
|
||||
int argc, FAR char **argv);
|
||||
#endif
|
||||
static int cmd_exec(FAR struct action_manager_s *am,
|
||||
int argc, FAR char **argv);
|
||||
static int cmd_class_start(FAR struct action_manager_s *am,
|
||||
|
|
@ -76,6 +81,9 @@ static const struct cmd_map_s g_builtin[] =
|
|||
{"class_stop", 2, 2, cmd_class_stop},
|
||||
{"exec", 3, 99, cmd_exec},
|
||||
{"exec_start", 2, 2, cmd_exec_start},
|
||||
#if CONFIG_SYSTEM_NXINIT_ACTION_EVENTS_MAX > 1
|
||||
{"setprop", 3, 3, cmd_setprop},
|
||||
#endif
|
||||
{"start", 2, 2, cmd_start},
|
||||
{"stop", 2, 2, cmd_stop},
|
||||
{"trigger", 2, 2, cmd_trigger},
|
||||
|
|
@ -136,6 +144,14 @@ static int cmd_stop(FAR struct action_manager_s *am,
|
|||
return init_service_stop(service);
|
||||
}
|
||||
|
||||
#if CONFIG_SYSTEM_NXINIT_ACTION_EVENTS_MAX > 1
|
||||
static int cmd_setprop(FAR struct action_manager_s *am, int argc,
|
||||
FAR char **argv)
|
||||
{
|
||||
return init_property_set(am->prop, argv[1], argv[2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int cmd_trigger(FAR struct action_manager_s *am,
|
||||
int argc, FAR char **argv)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
#include "builtin.h"
|
||||
#include "init.h"
|
||||
#include "import.h"
|
||||
#include "property.h"
|
||||
#include "service.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -49,21 +50,6 @@
|
|||
: ((ts)->tv_sec = (ms) / 1000, \
|
||||
(ts)->tv_nsec = ((ms) % 1000) * 1000000, (ts)))
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct init_event_s
|
||||
{
|
||||
FAR struct pollfd *pfd;
|
||||
FAR void *priv;
|
||||
FAR struct service_manager_s *sm;
|
||||
FAR struct action_manager_s *am;
|
||||
CODE int (*init) (FAR struct init_event_s *);
|
||||
CODE void (*handle) (FAR struct init_event_s *);
|
||||
CODE void (*deinit) (FAR struct init_event_s *);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
|
@ -154,11 +140,16 @@ int main(int argc, FAR char *argv[])
|
|||
{NULL},
|
||||
};
|
||||
|
||||
struct init_event_s ev[] =
|
||||
struct init_poller_s poller[] =
|
||||
{
|
||||
{
|
||||
.init = init_property_init,
|
||||
.handle = init_property_handler,
|
||||
.deinit = init_property_deinit,
|
||||
},
|
||||
};
|
||||
|
||||
struct pollfd pfds[nitems(ev)];
|
||||
struct pollfd pfds[nitems(poller)];
|
||||
sigset_t mask;
|
||||
size_t i;
|
||||
int r;
|
||||
|
|
@ -176,12 +167,12 @@ int main(int argc, FAR char *argv[])
|
|||
usbtrace_enable(TRACE_BITSET);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < nitems(ev); i++)
|
||||
for (i = 0; i < nitems(poller); i++)
|
||||
{
|
||||
ev[i].sm = &sm;
|
||||
ev[i].am = &am;
|
||||
ev[i].pfd = &pfds[i];
|
||||
r = ev[i].init(&ev[i]);
|
||||
poller[i].sm = &sm;
|
||||
poller[i].am = &am;
|
||||
poller[i].pfd = &pfds[i];
|
||||
r = poller[i].init(&poller[i]);
|
||||
if (r < 0)
|
||||
{
|
||||
init_err("Init event %zu", i);
|
||||
|
|
@ -237,11 +228,11 @@ int main(int argc, FAR char *argv[])
|
|||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < nitems(ev); i++)
|
||||
for (i = 0; i < nitems(poller); i++)
|
||||
{
|
||||
if (ev[i].pfd->revents & ev[i].pfd->events)
|
||||
if (poller[i].pfd->revents & poller[i].pfd->events)
|
||||
{
|
||||
ev[i].handle(&ev[i]);
|
||||
poller[i].handle(&poller[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -251,9 +242,9 @@ int main(int argc, FAR char *argv[])
|
|||
out:
|
||||
while (i--)
|
||||
{
|
||||
if (ev[i].deinit)
|
||||
if (poller[i].deinit)
|
||||
{
|
||||
ev[i].deinit(&ev[i]);
|
||||
poller[i].deinit(&poller[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <poll.h>
|
||||
#include <syslog.h>
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -90,4 +91,19 @@
|
|||
} \
|
||||
while (0)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct init_poller_s
|
||||
{
|
||||
FAR struct pollfd *pfd;
|
||||
FAR void *priv;
|
||||
FAR struct service_manager_s *sm;
|
||||
FAR struct action_manager_s *am;
|
||||
CODE int (*init) (FAR struct init_poller_s *);
|
||||
CODE void (*handle) (FAR struct init_poller_s *);
|
||||
CODE void (*deinit) (FAR struct init_poller_s *);
|
||||
};
|
||||
|
||||
#endif /* __APPS_SYSTEM_NXINIT_INIT_H */
|
||||
|
|
|
|||
49
system/nxinit/property.h
Normal file
49
system/nxinit/property.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/****************************************************************************
|
||||
* apps/system/nxinit/property.h
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_SYSTEM_NXINIT_PROPERTY_H
|
||||
#define __APPS_SYSTEM_NXINIT_PROPERTY_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "init.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Steps to enable action events
|
||||
*
|
||||
* - Define all init_property_*() interfaces declared in this file.
|
||||
* - Data structures or functions that will likely be used:
|
||||
* - struct action_event_s
|
||||
* - init_action_foreach_event()
|
||||
*/
|
||||
|
||||
void init_property_handler(FAR struct init_poller_s *ctx);
|
||||
void init_property_deinit(FAR struct init_poller_s *ctx);
|
||||
int init_property_init(FAR struct init_poller_s *ctx);
|
||||
int init_property_set(FAR struct init_poller_s *ctx,
|
||||
FAR const char *key, FAR const char *value);
|
||||
#endif /* __APPS_SYSTEM_NXINIT_PROPERTY_H */
|
||||
57
system/nxinit/property_simple.c
Normal file
57
system/nxinit/property_simple.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/****************************************************************************
|
||||
* apps/system/nxinit/property_simple.c
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "action.h"
|
||||
#include "property.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int init_property_set(FAR struct init_poller_s *ctx,
|
||||
FAR const char *key, FAR const char *value)
|
||||
{
|
||||
init_debug("Setprop key:%s value:%s", key, value);
|
||||
init_action_trigger_event(ctx->am, key, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_property_handler(FAR struct init_poller_s *ctx)
|
||||
{
|
||||
UNUSED(ctx);
|
||||
}
|
||||
|
||||
void init_property_deinit(FAR struct init_poller_s *ctx)
|
||||
{
|
||||
UNUSED(ctx);
|
||||
}
|
||||
|
||||
int init_property_init(FAR struct init_poller_s *ctx)
|
||||
{
|
||||
ctx->am->prop = ctx;
|
||||
ctx->pfd->fd = -1;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue