Пример #1
0
static int test_8_UpdateNotification()
{
    swi_status_t res;
    swi_av_Asset_t* asset = NULL;
    waiting_notification = 1;

    res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;
    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;
    res = swi_av_RegisterUpdateNotification(asset, (swi_av_updateNotificationCB) updateNotificationCb, "userData");
    if (res != SWI_STATUS_OK)
        return res;

    const char *cmd_SoftwareUpdate ="'SoftwareUpdate', { 'TOTO.my_pkg', 'my_version', '/toto/my_file', {foo='bar', num=42, float=0.23}})\n";
    exec_lua_code(cmd_SoftwareUpdate);
    SWI_LOG("AV_TEST", DEBUG, "exec_lua_code SoftwareUpdate done\n");
    while (waiting_notification)
        ;

    swi_av_asset_Destroy(asset);
    if (res != SWI_STATUS_OK)
        return res;

    return result;
}
Пример #2
0
int sampleMain()
{
    swi_av_Asset_t *asset = NULL;
    swi_av_Table_t *table = NULL;
    rc_ReturnCode_t res;

    const char *columns[] = {
          "col1",
          "col2",
          "timestamp"
        };

    res = swi_av_Init();
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to initialize airvantage module\n");
        return 1;
    }

    LE_INFO("Initializing asset\n");
    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to create asset\n");
        return 1;
    }

    LE_INFO("Registering asset\n");
    res = swi_av_asset_Start(asset);
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to register asset module\n");
        return 1;
    }

    res = swi_av_asset_PushString(asset, "event.status", "now", SWI_AV_TSTAMP_AUTO, "booting");
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to push data\n");
        return 1;
    }

    res = swi_av_table_Create(asset, &table, "col.data", 3, columns, POLICY, STORAGE_RAM, 0);
    if (res != RC_OK)
    {
        fprintf(stderr, "Failed to create table bedroom.data\n");
        return 1;
    }

    AddBedroomData(asset, table, 10);
    sleep(2);

    swi_av_asset_Destroy(asset);

    swi_av_Destroy();
    return 0;
}
Пример #3
0
static int test_4_asset_Create_Start_Destroy()
{
  rc_ReturnCode_t res = swi_av_Init();
  if (res != RC_OK)
    return res;

  swi_av_Asset_t* asset;
  /*
   res = swi_av_asset_Create(&asset, NULL);
   if (res != RC_BAD_PARAMETER)
   return 1;

   res = swi_av_asset_Create(NULL, "test_asset");
   if (res != RC_BAD_PARAMETER)
   return 1;
   */
  res = swi_av_asset_Create(&asset, ASSET_ID);
  if (res != RC_OK)
    return res;

  res = swi_av_asset_Start(NULL );
  if (res != RC_BAD_PARAMETER)
    return res;

  res = swi_av_asset_Start(asset);
  if (res != RC_OK)
    return res;

  res = swi_av_asset_Destroy(NULL);
  if (res != RC_BAD_PARAMETER)
    return res;

  res = swi_av_asset_Destroy(asset);
  if (res != RC_OK)
    return res;

  res = swi_av_Destroy();
  if (res != RC_OK)
    return res;

  return RC_OK;
}
Пример #4
0
static int test_4_asset_Create_Start_Destroy()
{
    swi_status_t res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    swi_av_Asset_t* asset;
    /*
     res = swi_av_asset_Create(&asset, NULL);
     if (res != SWI_STATUS_WRONG_PARAMS)
     return 1;

     res = swi_av_asset_Create(NULL, "test_asset");
     if (res != SWI_STATUS_WRONG_PARAMS)
     return 1;
     */
    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;
    res = swi_av_asset_Start(NULL );
    if (res != SWI_STATUS_CONTEXT_IS_CORRUPTED)
        return res;

    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Destroy(NULL );
    if (res != SWI_STATUS_CONTEXT_IS_CORRUPTED)
        return res;

    res = swi_av_asset_Destroy(asset);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    return 0;
}
Пример #5
0
static int test_9_TableManipulation()
{
    swi_status_t res;
    swi_av_Asset_t* asset = NULL;
    swi_av_Table_t *table = NULL;
    const char *columns[] = { "column1", "column2", "column3" };

    res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_table_Create(asset, &table, "test", 3, columns, "now", STORAGE_RAM, 0);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_table_PushInteger(table, 1234);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_table_PushFloat(table, 1234.1234);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_table_PushString(table, "test");
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_table_PushString(table, "fake push");
    if (res != SWI_STATUS_VALUE_OUT_OF_BOUND)
        return res;

    res = swi_av_table_PushRow(table);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_table_Destroy(table);
    if (res != SWI_STATUS_OK)
        return res;
    swi_av_asset_Destroy(asset);
    return 0;
}
Пример #6
0
static int test_10_asset_receiveDataWriting()
{
    swi_status_t res = SWI_STATUS_OK;
    waiting_notification = 1;

    res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    swi_av_Asset_t* asset;

    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_RegisterDataWrite(asset, dwcb_DataWritting, NULL );
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;

    /*command sends to TOTO asset*/
    const char* str = "'SendData', { Path = 'TOTO.sub.path', Body = { foo = 'bar' }, TicketId = %u, Type = 5, __class = 'AWT-DA::Message' })\n";
    char* cmd_SendDataWriting = addTicketId(str);

    exec_lua_code(cmd_SendDataWriting);
    SWI_LOG("AV_TEST", DEBUG, "exec_lua_code SendDataWriting done\n");
    while (waiting_notification)
        ;

    res = swi_av_asset_Destroy(asset);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    free(cmd_SendDataWriting);
    return result;
}
Пример #7
0
static int test_12_asset_receiveDataCommandList()
{
  rc_ReturnCode_t res = RC_OK;
  waiting_notification = 1;

  res = swi_av_Init();
  if (res != RC_OK)
    return res;

  swi_av_Asset_t* asset;

  res = swi_av_asset_Create(&asset, ASSET_ID);
  if (res != RC_OK)
    return res;

  res = swi_av_RegisterDataWrite(asset, dwcb_DataCommandList, NULL );
  if (res != RC_OK)
    return res;

  res = swi_av_asset_Start(asset);
  if (res != RC_OK)
    return res;

  const char* str = "'SendData', { Path = 'av_test_asset_id.sub.path', Body = { Command = 'plop',  Args = {42, 'bar'}, __class = 'AWT-DA::Command' },  TicketId = %u, Type = 2,  __class = 'AWT-DA::Message' })\n";
  char* cmd_SendDataCommandList = addTicketId(str);

  exec_lua_code(cmd_SendDataCommandList);
  SWI_LOG("AV_TEST", DEBUG, "exec_lua_code SendDataCommandList done\n");
  while (waiting_notification)
    ;

  res = swi_av_asset_Destroy(asset);
  if (res != RC_OK)
    return res;

  res = swi_av_Destroy();
  if (res != RC_OK)
    return res;

  free(cmd_SendDataCommandList);
  return result;
}
Пример #8
0
static int test_5_asset_pushData()
{

    swi_status_t res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return 1;

    swi_av_Asset_t* asset;

    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;

//"long" path
    res = swi_av_asset_PushInteger(asset, "titi.test.toto1", "now", SWI_AV_TSTAMP_AUTO, 42);
    if (res != SWI_STATUS_OK)
        return res;
//"short" path
    res = swi_av_asset_PushInteger(asset, "titi.toto2", "now", SWI_AV_TSTAMP_AUTO, 43);
    if (res != SWI_STATUS_OK)
        return res;
//"shortest" path
    res = swi_av_asset_PushInteger(asset, "toto3", "now", SWI_AV_TSTAMP_AUTO, 44);
    if (res != SWI_STATUS_OK)
        return res;
//"shortest" path, no timestamp
    res = swi_av_asset_PushInteger(asset, "toto4", "now", SWI_AV_TSTAMP_NO, 45);
    if (res != SWI_STATUS_OK)
        return res;
//"shortest" path, no timestamp, no policy
    res = swi_av_asset_PushInteger(asset, "toto5", NULL, SWI_AV_TSTAMP_AUTO, 46);
    if (res != SWI_STATUS_OK)
        return res;
//"shortest" path, manual timestamp, no policy
    res = swi_av_asset_PushInteger(asset, "toto6", NULL, 23, 47);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_PushFloat(asset, "toto7", "now", SWI_AV_TSTAMP_AUTO, 47.455555);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_PushString(asset, "toto8", "now", SWI_AV_TSTAMP_AUTO, "foo");
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_PushString(asset, "toto8", "now", SWI_AV_TSTAMP_AUTO, NULL );
    if (res != SWI_STATUS_WRONG_PARAMS)
        return res;

    res = swi_av_TriggerPolicy("*");
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Destroy(asset);
    if (res != SWI_STATUS_OK)
        return res;

    return 0;
}