Example #1
0
int
oc_main_init(oc_handler_t *handler)
{
    int ret;
    extern int oc_stack_errno;

    if (initialized == true) {
        return 0;
    }
    oc_ri_init();

#ifdef OC_SECURITY
    handler->get_credentials();

    oc_sec_load_pstat();
    oc_sec_load_doxm();
    oc_sec_load_cred();

    oc_sec_dtls_init_context();
#endif

    ret = oc_connectivity_init();
    if (ret < 0) {
        goto err;
    }
    handler->init();

#ifdef OC_SERVER
    if (handler->register_resources) {
        handler->register_resources();
    }
#endif

#ifdef OC_SECURITY
    oc_sec_create_svr();
    oc_sec_load_acl();
#endif

    if (oc_stack_errno != 0) {
        ret = -oc_stack_errno;
        goto err;
    }

    OC_LOG_INFO("oci: Initialized\n");

#ifdef OC_CLIENT
    handler->requests_entry();
#endif

    initialized = true;
    return 0;

err:
    oc_abort("oc_main: Error in stack initialization\n");
    return ret;
}
Example #2
0
int
oc_main_init(oc_handler_t *handler)
{
  int ret;
  extern int oc_stack_errno;

  if (initialized == true)
    return 0;

  oc_ri_init();

#ifdef OC_SECURITY
  handler->get_credentials();

  oc_sec_load_pstat();
  oc_sec_load_doxm();
  oc_sec_load_cred();

  oc_sec_dtls_init_context();
#endif

  oc_network_event_handler_mutex_init();
  ret = oc_connectivity_init();
  if (ret < 0)
    goto err;

  handler->init();

#ifdef OC_SERVER
  handler->register_resources();
#endif

#ifdef OC_SECURITY
  oc_sec_create_svr();
  oc_sec_load_acl();
#endif

  if (oc_stack_errno != 0) {
    ret = -oc_stack_errno;
    goto err;
  }

  PRINT("oc_main: Stack successfully initialized\n");

#ifdef OC_CLIENT
  handler->requests_entry();
#endif

  initialized = true;
  return 0;

err:
  oc_abort("oc_main: Error in stack initialization\n");
  return ret;
}