Changeset 479

Show
Ignore:
Timestamp:
09/18/09 10:25:13 (15 years ago)
Author:
bhilburn
Message:

A few changes to the SML which might be necessary for the sql code to
work properly.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp

    r465 r479  
    108108 
    109109 
    110 /* Useful for spotchecking what's in the database */ 
    111 void 
    112 printDatabase()  
    113 { 
    114     /* 
    115     LOG("\n\n\n"); 
    116     data_DB->command = "select "; 
    117     data_DB->command.append(data_DB->tablename); 
    118     data_DB->command.append(".* from "); 
    119     data_DB->command.append(data_DB->tablename); 
    120     data_DB->command.append(";"); 
    121  
    122     char *errorMsg; 
    123     int32_t rc = sqlite3_exec(data_DB->db, data_DB->command.c_str(), callback, 0, &errorMsg); 
    124     if((rc != SQLITE_OK) && (rc != 101)) 
    125         WARNING("SQL error: %s\n", errorMsg); 
    126  
    127     LOG("database %s, table %s:\n", data_DB->filename, data_DB->tablename); 
    128     LOG("\n\n\n"); 
    129     */ 
    130 } 
    131  
    132110ServiceManagementLayer::ServiceManagementLayer() 
    133111{ 
     
    139117    cogEngSrv = 1; 
    140118} 
     119 
    141120 
    142121/* Free and clear the DB's associated with this SML in the destructor. 
     
    177156} 
    178157 
     158 
    179159/* Note that sizes of CE_List, miss, and service are hardcoded for now. 
    180160 * Also, their sizes are hardcoded into the code in various places; a fix  
     
    204184} 
    205185 
     186 
    206187/* CALLED BY: constructor 
    207188 * INPUTS: <none> 
     
    221202    sqlite3_open(services_DB->filename.c_str(), &(services_DB->db)); 
    222203 
    223     char *cols[] = {(char *)"ID_Num", (char *)"Service_Name"}; 
    224  
    225204    services_DB->tablename="Services"; 
    226205 
    227     /* ifprogram execution ends in anything other than a ordered shutdown, DB's will still  
     206    /* If program execution ends in anything other than a ordered shutdown, DB's will still  
    228207     * be there for next run. Need to get rid of it so that old data isn't inadvertantly  
    229208     * used in the next execution cycle. */ 
    230     services_DB->command = "DROP TABLE ifEXISTS Services;";      
     209    services_DB->command = "DROP TABLE if EXISTS Services;";      
    231210 
    232211    rc = sqlite3_prepare_v2(services_DB->db, services_DB->command.c_str(), 128, &ppStmt, &pzTail); 
     
    243222    services_DB->command="CREATE TABLE "; 
    244223    services_DB->command.append(services_DB->tablename); 
    245     services_DB->command.append("("); 
    246     services_DB->command.append(cols[0]); 
    247     services_DB->command.append(" INT, "); 
    248     services_DB->command.append(cols[1]); 
    249     services_DB->command.append(" TEXT);"); 
     224    services_DB->command.append("(ID_Num INT, Service_Name TEXT);"); 
    250225 
    251226    /* Execute create table command */ 
     
    259234} 
    260235 
     236 
    261237/* CALLED BY: constructor 
    262238 * INPUTS: <none> 
     
    277253    sqlite3_open(data_DB->filename.c_str(), &(data_DB->db)); 
    278254 
    279     char *cols[] = {(char *)"Tag", (char *)"Data"}; 
    280  
    281255    data_DB->tablename = "Data"; 
    282     data_DB->command = "DROP TABLE ifEXISTS Data;";      
     256    data_DB->command = "DROP TABLE if EXISTS Data;";      
    283257 
    284258    rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), 128, &ppStmt, &pzTail); 
     
    292266    data_DB->num_columns = 2; 
    293267 
    294     /* Generate command */ 
     268    /* First column is the name of the data (corresponding to the name of the output/input pair) 
     269     * It is the primary key so any subsequent data with the same name will replace the row. */ 
    295270    data_DB->command = "CREATE TABLE "; 
    296271    data_DB->command.append(data_DB->tablename); 
    297     data_DB->command.append("("); 
    298     data_DB->command.append(cols[0]); 
    299  
    300     /* First column is the name of the data (corresponding to the name of the output/input pair) 
    301      * It is the primary key so any subsequent data with the same name will replace the row. */ 
    302     data_DB->command.append(" TEXT PRIMARY KEY ON CONFLICT REPLACE, "); 
    303     data_DB->command.append(cols[1]); 
    304     data_DB->command.append(" TEXT);"); 
     272    data_DB->command.append("(Tag TEXT PRIMARY KEY ON CONFLICT REPLACE, Data TEXT);"); 
    305273 
    306274    rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), 128, &ppStmt, &pzTail); 
     
    313281} 
    314282 
     283 
    315284/* CALLED BY: MessageHandler 
    316285 * INPUTS: <none> 
     
    325294    LOG("SML responded to GetRemoteComponentType query.\n"); 
    326295} 
     296 
    327297 
    328298/* CALLED BY: constructor 
     
    342312    RegisterComponent(); 
    343313} 
     314 
    344315 
    345316/* CALLED BY: StartSMLServer 
     
    363334 
    364335    ReadMessage(_FD, buffer); 
    365      
    366     //--------Policy Engine Stuff - no policy engine support in this version-------// 
    367  
    368     //printf("********* %s **********\n", buffer); 
    369     // TODO 
    370     // ifwe send integer op codes rather than strings, this process will be 
    371     // MUCH faster since instead of donig string compares we can simply 
    372     // switch on the integer value... 
    373     /*if(strcmp(buffer, "register_service") == 0) { 
    374         if(strcmp(buffer, "policy_geo") == 0) { 
    375         } 
    376         else if(strcmp(buffer, "policy_time") == 0) { 
    377         } 
    378         else if(strcmp(buffer, "policy_spectrum") == 0) { 
    379         } 
    380         else if(strcmp(buffer, "policy_spacial") == 0) { 
    381         } 
    382     } 
    383     else if(strcmp(buffer, "deregister_service") == 0) { 
    384         if(strcmp(buffer, "policy_geo") == 0) { 
    385         } 
    386         else if(strcmp(buffer, "policy_time") == 0) { 
    387         } 
    388         else if(strcmp(buffer, "policy_spectrum") == 0) { 
    389         } 
    390         else if(strcmp(buffer, "policy_spacial") == 0) { 
    391         } 
    392     }*/ 
    393  
    394     //Go down the list to call the appropriate function 
     336    
     337    /* Go down the list to call the appropriate function */ 
    395338    if(strcmp(buffer, "query_component_type") == 0) { 
    396339        SendComponentType(); 
     
    428371} 
    429372 
    430 //TODO Finish 
     373 
    431374/* CALLED BY: MessageHandler 
    432375 * INPUTS: <none> 
     
    441384} 
    442385 
    443 //TODO Finish 
     386 
    444387/* CALLED BY: MessageHandler 
    445388 * INPUTS: <none> 
     
    455398} 
    456399 
     400 
    457401/* CALLED BY: ConnectToShell 
    458402 * INPUTS: <none> 
     
    467411    LOG("ServiceManagementLayer:: Registration message sent.\n"); 
    468412} 
     413 
    469414 
    470415/* CALLED BY: Shutdown 
     
    571516} 
    572517 
     518 
    573519/* CALLED BY: MessageHandler 
    574520 * INPUTS: |ID| The ID number of the component where service is located 
     
    584530    ReadMessage(CE_List[ID].FD, buffer); 
    585531 
    586     char *cols[] = {(char *) "ID_Num", (char *) "Service_Name"}; 
    587  
    588532    /* Generate command */ 
    589533    services_DB->command = "insert into "; 
    590534    services_DB->command.append(services_DB->tablename);  
    591     services_DB->command.append(" ("); 
    592     services_DB->command.append(cols[0]); 
    593     services_DB->command.append(", "); 
    594     services_DB->command.append(cols[1]); 
    595     services_DB->command.append(") "); 
    596     services_DB->command.append(" values("); 
     535    services_DB->command.append(" (ID_Num, Service_Name) values("); 
    597536 
    598537    char temp[3]; 
     
    611550        WARNING("ServiceManagementLayer::RecieveServices DB Error %s\n", errorMsg); 
    612551} 
     552 
    613553 
    614554/* CALLED BY: MessageHandler 
     
    682622} 
    683623 
     624 
    684625/* CALLED BY: PerformActiveMission 
    685626 * INPUTS: |sourceID| ID of the service that is being processed 
     
    699640    char buffer[256]; 
    700641    std::string data; 
    701     char *cols[] = {(char *) "Tag", (char *) "Data"}; 
    702642    char *token; 
    703643 
     
    795735    int32_t rc; 
    796736    char *errorMsg; 
    797     char *cols[] = {(char *) "Tag", (char *) "Data"}; 
    798737 
    799738    LOG("ServiceManagementLayer:: Received PerformActiveMission command.\n"); 
     
    812751        data_DB->command="insert into "; 
    813752        data_DB->command.append(data_DB->tablename);  
    814         data_DB->command.append(" ("); 
    815         data_DB->command.append(cols[0]); 
    816         data_DB->command.append(", "); 
    817         data_DB->command.append(cols[1]); 
    818         data_DB->command.append(") "); 
     753        data_DB->command.append(" (Tag, Data) "); 
    819754 
    820755        memset(buffer, 0, 256); 
     
    13001235} 
    13011236 
     1237 
    13021238/* CALLED BY: Reset 
    13031239 * INPUTS: <none> 
     
    13191255    LoadConfiguration(_SML_Config.c_str(), miss); 
    13201256} 
     1257 
    13211258 
    13221259/* CALLED BY: constructor 
     
    14981435} 
    14991436 
     1437 
    15001438/* CALLED BY: MessageHandler 
    15011439 * INPUTS: |ID| The ID number of the engine to be registered 
     
    15221460    CE_Present = true; 
    15231461} 
     1462 
    15241463 
    15251464/* CALLED BY: MessageHandler 
     
    15581497        WARNING("SQL error: %s\n", errorMsg); 
    15591498} 
     1499 
    15601500 
    15611501/* CALLED BY: MessageHandler