예제 #1
1
void ubus_init()
{
  struct ubus_context *ubus = NULL;
  int ret = 0;

  ubus = ubus_connect(NULL);
  if (!ubus)
    {
      if (!error_logged)
        {
          my_syslog(LOG_ERR, _("Cannot initialize UBus: connection failed"));
          error_logged = 1;
        }

      ubus_destroy(ubus);
      return;
    }

  ret = ubus_add_object(ubus, &ubus_object);
  if (ret)
    {
      if (!error_logged)
        {
          my_syslog(LOG_ERR, _("Cannot add object to UBus: %s"), ubus_strerror(ret));
          error_logged = 1;
        }
      return;
    }

  ubus->connection_lost = ubus_disconnect_cb;
  daemon->ubus = ubus;
  error_logged = 0;

  my_syslog(LOG_INFO, _("Connected to system UBus"));
}
int main(int argc, char **argv)
{
    const char *ubus_socket = NULL;
    int ch;
    while ((ch = getopt(argc, argv, "cs:")) != -1) {
        switch (ch) {
            case 's':
                ubus_socket = optarg;
                break;
            default:
                break;
        }
    }
    argc -= optind;
    argv += optind;
    uloop_init();
    //N1.  Connect the process to ubus daemon
    ctx = ubus_connect(ubus_socket);
    if (!ctx) {
        fprintf(stderr, "Failed to connect to ubus\n");
        return -1;
    }
    //N2.  Add connected fd into epoll fd set
    ubus_add_uloop(ctx);
    //N4.  Add notify object onto bus
    ubus_add_object(ctx, & test_object);
    //N5.  Prepare notify type and arguments when actually an  event happens 
    ……
        event_ broadcast(event);

    ubus_free(ctx);
    uloop_done();
    return 0;
} 
예제 #3
0
파일: vlan.c 프로젝트: sevennothing/lros
void vlan_add_to_ubus(void)
{
	int ret;

	ret = ubus_add_object(ctx, &vlan_object);
	if (ret)
		ERROR(GLOBAL_OUT_GROUP,"Failed to add port object: %s\n", ubus_strerror(ret));

};
예제 #4
0
static void server_main(void)
{
    int ret;

    ret = ubus_add_object(ctx, &apClient_object);
    if (ret) fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret));

    uloop_run();
}
예제 #5
0
int ubus_register_subscriber(struct ubus_context *ctx, struct ubus_subscriber *s)
{
	struct ubus_object *obj = &s->obj;

	obj->methods = &watch_method;
	obj->n_methods = 1;

	return ubus_add_object(ctx, obj);
}
예제 #6
0
파일: main.c 프로젝트: OnionIoT/ogps
static void
ubus_connect_handler(struct ubus_context *ctx)
{
	int ret;

	ret = ubus_add_object(ctx, &gps_object);
	if (ret)
		fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret));
}
예제 #7
0
void lowlevel_add_to_ubus(void)
{
	int ret;

	ret = ubus_add_object(ctx, &lowlevel_object);
	if (ret)
		ERROR(GLOBAL_OUT_GROUP,"Failed to add port authorized object: %s\n", ubus_strerror(ret));

};
예제 #8
0
int
ubus_init(void)
{
	ctx = ubus_connect(config->local->ubus_socket);
	if (!ctx) return -1;

	ubus_add_uloop(ctx);

	if (ubus_add_object(ctx, &main_object)) return -1;

	return 0;
}
예제 #9
0
int
ubus_init(void)
{
	ubus = ubus_connect(NULL);

	if (!ubus) return -1;

	ubus_add_uloop(ubus);

	if (ubus_add_object(ubus, &main_object)) return -1;

	return 0;
}
예제 #10
0
void ubus_init_system(struct ubus_context *ctx)
{
	struct stat s;
	int ret;

	if (stat("/sbin/upgraded", &s))
		system_object.n_methods -= 1;

	_ctx = ctx;
	ret = ubus_add_object(ctx, &system_object);
	if (ret)
		ERROR("Failed to add object: %s\n", ubus_strerror(ret));
}
예제 #11
0
파일: ubus.c 프로젝트: gaojing2016/backup
int cloudc_ubus_init(void)
{
    int ret = -1;
    const char *ubus_socket = NULL;

    cloudc_debug("%s[%d]: Enter ", __func__, __LINE__);
    uloop_init();

    /* ubus init */
    cloudc_ctx = ubus_connect(ubus_socket);

    if (!cloudc_ctx) 
    {    
        cloudc_error(stderr, "Failed to connect to ubus");
        return -1;
    }    

    else 
    {    
        cloudc_debug("%s[%d]: connect to ubus succeed, cloudc_ctx = %p", __func__, __LINE__, cloudc_ctx);
    }    

    /* add connected fd into epoll fd set */
    ubus_add_uloop(cloudc_ctx); 

    /* add ubus object */
    ret = ubus_add_object(cloudc_ctx, &cloudc_object);

    if (ret)
    {    

        cloudc_error(stderr, "Failed to add object: %s", ubus_strerror(ret));
    }    
    else 
    {    
        cloudc_debug("%s[%d]: ubus add object successfully, ret = %d", __func__, __LINE__, ret);
    }    

    cloudc_debug("%s[%d]: Exit ", __func__, __LINE__);
    return 0;

}
예제 #12
0
파일: rrdns.c 프로젝트: jow-/luci-ng
static int
rpc_rrdns_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx)
{
    static const struct ubus_method rrdns_methods[] = {
        UBUS_METHOD("lookup", rpc_rrdns_lookup, rpc_lookup_policy),
    };

    static struct ubus_object_type rrdns_type =
        UBUS_OBJECT_TYPE("luci-rpc-rrdns", rrdns_methods);

    static struct ubus_object obj = {
        .name = "luci2.network.rrdns",
        .type = &rrdns_type,
        .methods = rrdns_methods,
        .n_methods = ARRAY_SIZE(rrdns_methods),
    };

    return ubus_add_object(ctx, &obj);
}

struct rpc_plugin rpc_plugin = {
    .init = rpc_rrdns_api_init
};