/** * Called from PL_HashTableEnumerateEntries * A pointer to a PatternEntry is passed in. A PatternEntry consists of * a pointer a regex_t and a pointer to a new config store. * Once enumeration is complete, the new config store will contain * all the parameters (key and values) whose keys match the regex. */ static PRIntn PatternLoop(PLHashEntry *he, PRIntn index, void *arg) { PatternEntry_t *entry = (PatternEntry_t *) arg; if (entry == NULL) { return HT_ENUMERATE_STOP; } regex_t *r = entry->regex; ConfigStore *store = entry->store; if ((r == NULL) || (store == NULL)) { return HT_ENUMERATE_STOP; } size_t no_sub = r->re_nsub+1; regmatch_t *result = NULL; result = (regmatch_t *) PR_Malloc(sizeof(regmatch_t) * no_sub); if ((he != NULL) && (he->key != NULL) && (he->value != NULL)) { if (regexec(r, (char *) he->key, no_sub, result, 0)==0) { // Found a match store->Add((const char*) he->key, (const char *) he->value); } } else { return HT_ENUMERATE_STOP; } if (result != NULL) PR_Free(result); return HT_ENUMERATE_NEXT; }
// Synchronize a new note with what is in the database. We basically // just delete the old one & give it a new entry void NoteTable::sync(qint32 lid, Note ¬e) { // QLOG_TRACE() << "Entering NoteTable::sync()"; if (lid > 0) { QSqlQuery query; // Delete the old record query.prepare("Delete from DataStore where lid=:lid and key>=3000 and key<3200"); query.bindValue(":lid", lid); query.exec(); ResourceTable resTable; for (unsigned int i=0;i<note.resources.size(); i++) { qint32 resLid = resTable.getLid(note.resources[i].noteGuid, note.resources[i].guid); query.bindValue(":lid", resLid); query.exec(); } } else { ConfigStore cs; lid = cs.incrementLidCounter(); } add(lid, note, false); //QLOG_TRACE() << "Leaving NoteTable::sync()"; }
void Garnet::convertIVGraphToPPEGraph(Garnet::IVGraph& iv, Garnet::PPEGraph& pg) { ConfigStore conf; TraceStore trace; conf.write("/convertIVGraphToPPEGraph/Remove Introns/ShouldRemoveIntrons", true); convertIVGraphToPPEGraph(iv, pg, conf, trace); }
void Garnet::generateScript(Garnet::PPEGraph& pg, std::ostream& outs) { ConfigStore conf; TraceStore trace; conf.write("/generateScript/Generate Script/TopologicalSortMethod", TOPOSORT_DEFAULT); Garnet::generateScript(pg, outs, conf, trace); }
ConfigStore *ConfigStore::CreateFromConfigFile(const char *cfg_path) { PRFileDesc *f = NULL; int removed_return; char line[MAX_CFG_LINE_LEN]; ConfigStoreRoot *root = NULL; ConfigStore *cfg = NULL; f = PR_Open(cfg_path, PR_RDWR, 00400|00200); if (f == NULL) goto loser; root = new ConfigStoreRoot(); cfg = new ConfigStore(root,""); while (1) { int n = ReadLine(f, line, MAX_CFG_LINE_LEN, &removed_return); if (n > 0) { if (line[0] == '#') // handle comment line continue; int c = 0; while ((c < n) && (line[c] != '=')) { c++; } if (c < n) { line[c] = '\0'; } else { continue; /* no '=', skip this line */ } cfg->Add(line, &line[c+1]); } else if (n == 0 && removed_return == 1) { continue; /* skip empty line */ } else { break; } } if( f != NULL ) { PR_Close( f ); f = NULL; } cfg->SetFilePath(cfg_path); loser: return cfg; }
void SharedNotebookTable::sync(qint32 l, SharedNotebook sharedNotebook){ qint32 lid = l; if (lid == 0) lid= findById(sharedNotebook.id); if (lid > 0) { QSqlQuery query; // Delete the old record query.prepare("Delete from DataStore where lid=:lid and key>=3300 and key <3400"); query.bindValue(":lid", lid); query.exec(); } else { ConfigStore cs; lid = cs.incrementLidCounter(); } add(lid, sharedNotebook, false); }
/** * Takes in a string containing a regular expression. * Returns a new ConfigStore which contains only those parameters whose * keys match the pattern. * The new Configstore must of course be freed by the caller. **/ ConfigStore *ConfigStore::GetPatternSubStore(const char *pattern) { ConfigStoreRoot *root = NULL; ConfigStore *ret = NULL; PatternEntry_t entry; regex_t *regex = NULL; int err_no=0; /* For regerror() */ regex = (regex_t *) malloc(sizeof(regex_t)); memset(regex, 0, sizeof(regex_t)); if((err_no=regcomp(regex, pattern, 0))!=0) /* Compile the regex */ { // Error in computing the regex size_t length; char *buffer; length = regerror (err_no, regex, NULL, 0); buffer = (char *) PR_Malloc(length); regerror (err_no, regex, buffer, length); // PR_fprintf(m_dump_f, "%s\n", buffer); /* Print the error */ PR_Free(buffer); regfree(regex); return NULL; } entry.regex = regex; root = new ConfigStoreRoot(); ret = new ConfigStore(root, ""); entry.store = ret; PR_Lock(m_lock); PL_HashTableEnumerateEntries(m_root->getSet(), &PatternLoop, &entry); PR_Unlock(m_lock); /* cleanup */ //regfree(entry.regex); //entry.store = NULL; ret->SetFilePath(""); return ret; }
// Synchronize a new notebook with what is in the database. We basically // just delete the old one & give it a new entry qint32 LinkedNotebookTable::sync(qint32 lid, LinkedNotebook ¬ebook) { qint32 lastUSN = 0; if (lid > 0) { lastUSN = getLastUpdateSequenceNumber(lid); // Delete the old record QSqlQuery query; query.prepare("Delete from DataStore where lid=:lid and key>=3200 and key<3300"); query.bindValue(":lid", lid); query.exec(); } else { ConfigStore cs; lid = cs.incrementLidCounter(); } add(lid, notebook, false); if (lastUSN > 0) { setLastUpdateSequenceNumber(lid, lastUSN); } return lid; }
int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); // to save a template default attribute file run it like this: // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Save --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lena-first-sim // // to load a previously created default attribute file // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Load --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lena-first-sim ConfigStore inputConfig; inputConfig.ConfigureDefaults (); // parse again so you can override default values from the command line cmd.Parse (argc, argv); Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel")); // Uncomment to enable logging //lteHelper->EnableLogComponents (); // Create Nodes: eNodeB and UE NodeContainer enbNodes; NodeContainer ueNodes; enbNodes.Create (1); ueNodes.Create (1); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes); BuildingsHelper::Install (ueNodes); // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; NetDeviceContainer ueDevs; // lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler"); lteHelper->SetSchedulerType ("ns3::PfFfMacScheduler"); lteHelper->SetSchedulerAttribute ("CqiTimerThreshold", UintegerValue (3)); enbDevs = lteHelper->InstallEnbDevice (enbNodes); ueDevs = lteHelper->InstallUeDevice (ueNodes); lteHelper->EnableRlcTraces(); lteHelper->EnableMacTraces(); // Attach a UE to a eNB lteHelper->Attach (ueDevs, enbDevs.Get (0)); Simulator::Schedule (Seconds (0.010), &ChangePosition, ueNodes.Get (0)); Simulator::Schedule (Seconds (0.020), &ChangePosition, ueNodes.Get (0)); // Activate a data radio bearer enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDevs, bearer); Simulator::Stop (Seconds (0.030)); Simulator::Run (); //GtkConfigStore config; //config.ConfigureAttributes (); Simulator::Destroy (); return 0; }
// Add a new notebook to the database qint32 LinkedNotebookTable::add(qint32 l, LinkedNotebook &t, bool isDirty) { QSqlQuery query; ConfigStore cs; qint32 lastUSN = 0; query.prepare("Insert into DataStore (lid, key, data) values (:lid, :key, :data)"); qint32 lid = l; if (lid == 0) { lid = cs.incrementLidCounter(); } query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_GUID); query.bindValue(":data", QString::fromStdString(t.guid)); query.exec(); if (t.__isset.shareName) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_SHARE_NAME); query.bindValue(":data", QString::fromStdString(t.shareName)); query.exec(); } if (t.__isset.username) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_USERNAME); query.bindValue(":data", QString::fromStdString(t.username)); query.exec(); } if (t.__isset.shardId) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_SHARD_ID); query.bindValue(":data", QString::fromStdString(t.shardId)); query.exec(); } if (t.__isset.shareKey) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_SHARE_KEY); query.bindValue(":data", QString::fromStdString(t.shareKey)); query.exec(); } if (t.__isset.uri) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_URI); query.bindValue(":data", QString::fromStdString(t.uri)); query.exec(); } if (t.__isset.updateSequenceNum) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_UPDATE_SEQUENCE_NUMBER); query.bindValue(":data", t.updateSequenceNum); query.exec(); } if (t.__isset.noteStoreUrl) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_NOTE_STORE_URL); query.bindValue(":data", QString::fromStdString(t.noteStoreUrl)); query.exec(); } if (t.__isset.webApiUrlPrefix) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_WEB_API_URL_PREFIX); query.bindValue(":data", QString::fromStdString(t.webApiUrlPrefix)); query.exec(); } if (t.__isset.stack) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_STACK); query.bindValue(":data", QString::fromStdString(t.stack)); query.exec(); } if (t.__isset.businessId) { query.bindValue(":lid", lid); query.bindValue(":key", LINKEDNOTEBOOK_BUSINESS_ID); query.bindValue(":data", t.businessId); query.exec(); } return lid; }
int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); // to save a template default attribute file run it like this: // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Save --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lena-first-sim // // to load a previously created default attribute file // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Load --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lena-first-sim ConfigStore inputConfig; inputConfig.ConfigureDefaults (); // Parse again so you can override default values from the command line cmd.Parse (argc, argv); Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); // Uncomment to enable logging //lteHelper->EnableLogComponents (); // Create Nodes: eNodeB and UE NodeContainer enbNodes; NodeContainer ueNodes; enbNodes.Create (1); ueNodes.Create (1); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes); BuildingsHelper::Install (ueNodes); // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; NetDeviceContainer ueDevs; // Default scheduler is PF, uncomment to use RR //lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler"); enbDevs = lteHelper->InstallEnbDevice (enbNodes); ueDevs = lteHelper->InstallUeDevice (ueNodes); // Attach a UE to a eNB lteHelper->Attach (ueDevs, enbDevs.Get (0)); // Activate an EPS bearer enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDevs, bearer); // Configure Radio Environment Map (REM) output // for LTE-only simulations always use /ChannelList/0 which is the downlink channel Ptr<RadioEnvironmentMapHelper> remHelper = CreateObject<RadioEnvironmentMapHelper> (); remHelper->SetAttribute ("ChannelPath", StringValue ("/ChannelList/0")); remHelper->SetAttribute ("OutputFile", StringValue ("rem.out")); remHelper->SetAttribute ("XMin", DoubleValue (-400.0)); remHelper->SetAttribute ("XMax", DoubleValue (400.0)); remHelper->SetAttribute ("YMin", DoubleValue (-300.0)); remHelper->SetAttribute ("YMax", DoubleValue (300.0)); remHelper->SetAttribute ("Z", DoubleValue (0.0)); remHelper->Install (); // here's a minimal gnuplot script that will plot the above: // // set view map; // set term x11; // set xlabel "X" // set ylabel "Y" // set cblabel "SINR (dB)" // plot "rem.out" using ($1):($2):(10*log10($4)) with image BuildingsHelper::MakeMobilityModelConsistent (); Simulator::Run (); //GtkConfigStore config; //config.ConfigureAttributes (); Simulator::Destroy (); return 0; }
int main (int argc, char *argv[]) { uint32_t nEnbPerFloor = 1; uint32_t nUe = 1; uint32_t nFloors = 0; double simTime = 1.0; CommandLine cmd; cmd.AddValue ("nEnb", "Number of eNodeBs per floor", nEnbPerFloor); cmd.AddValue ("nUe", "Number of UEs", nUe); cmd.AddValue ("nFloors", "Number of floors, 0 for Friis propagation model", nFloors); cmd.AddValue ("simTime", "Total duration of the simulation (in seconds)", simTime); cmd.Parse (argc, argv); ConfigStore inputConfig; inputConfig.ConfigureDefaults (); // parse again so you can override default values from the command line cmd.Parse (argc, argv); // Geometry of the scenario (in meters) // Assume squared building double nodeHeight = 1.5; double roomHeight = 3; double roomLength = 8; uint32_t nRooms = std::ceil (std::sqrt (nEnbPerFloor)); uint32_t nEnb; Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); //lteHelper->EnableLogComponents (); //LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL); if (nFloors == 0) { lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisPropagationLossModel")); nEnb = nEnbPerFloor; } else { lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel")); nEnb = nFloors * nEnbPerFloor; } // Create Nodes: eNodeB and UE NodeContainer enbNodes; std::vector<NodeContainer> ueNodes; enbNodes.Create (nEnb); for (uint32_t i = 0; i < nEnb; i++) { NodeContainer ueNode; ueNode.Create (nUe); ueNodes.push_back (ueNode); } MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); std::vector<Vector> enbPosition; Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); Ptr<Building> building; if (nFloors == 0) { // Position of eNBs uint32_t plantedEnb = 0; for (uint32_t row = 0; row < nRooms; row++) { for (uint32_t column = 0; column < nRooms && plantedEnb < nEnbPerFloor; column++, plantedEnb++) { Vector v (roomLength * (column + 0.5), roomLength * (row + 0.5), nodeHeight); positionAlloc->Add (v); enbPosition.push_back (v); mobility.Install (ueNodes.at(plantedEnb)); } } mobility.SetPositionAllocator (positionAlloc); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); // Position of UEs attached to eNB for (uint32_t i = 0; i < nEnb; i++) { Ptr<UniformRandomVariable> posX = CreateObject<UniformRandomVariable> (); posX->SetAttribute ("Min", DoubleValue (enbPosition.at(i).x - roomLength * 0.5)); posX->SetAttribute ("Max", DoubleValue (enbPosition.at(i).x + roomLength * 0.5)); Ptr<UniformRandomVariable> posY = CreateObject<UniformRandomVariable> (); posY->SetAttribute ("Min", DoubleValue (enbPosition.at(i).y - roomLength * 0.5)); posY->SetAttribute ("Max", DoubleValue (enbPosition.at(i).y + roomLength * 0.5)); positionAlloc = CreateObject<ListPositionAllocator> (); for (uint32_t j = 0; j < nUe; j++) { positionAlloc->Add (Vector (posX->GetValue (), posY->GetValue (), nodeHeight)); mobility.SetPositionAllocator (positionAlloc); } mobility.Install (ueNodes.at(i)); BuildingsHelper::Install (ueNodes.at(i)); } } else { building = CreateObject<Building> (); building->SetBoundaries (Box (0.0, nRooms * roomLength, 0.0, nRooms * roomLength, 0.0, nFloors* roomHeight)); building->SetBuildingType (Building::Residential); building->SetExtWallsType (Building::ConcreteWithWindows); building->SetNFloors (nFloors); building->SetNRoomsX (nRooms); building->SetNRoomsY (nRooms); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); uint32_t plantedEnb = 0; for (uint32_t floor = 0; floor < nFloors; floor++) { uint32_t plantedEnbPerFloor = 0; for (uint32_t row = 0; row < nRooms; row++) { for (uint32_t column = 0; column < nRooms && plantedEnbPerFloor < nEnbPerFloor; column++, plantedEnb++, plantedEnbPerFloor++) { Vector v (roomLength * (column + 0.5), roomLength * (row + 0.5), nodeHeight + roomHeight * floor); positionAlloc->Add (v); enbPosition.push_back (v); Ptr<MobilityModel> mmEnb = enbNodes.Get (plantedEnb)->GetObject<MobilityModel> (); mmEnb->SetPosition (v); // Positioning UEs attached to eNB mobility.Install (ueNodes.at(plantedEnb)); BuildingsHelper::Install (ueNodes.at(plantedEnb)); for (uint32_t ue = 0; ue < nUe; ue++) { Ptr<MobilityModel> mmUe = ueNodes.at(plantedEnb).Get (ue)->GetObject<MobilityModel> (); Vector vUe (v.x, v.y, v.z); mmUe->SetPosition (vUe); } } } } } // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; std::vector<NetDeviceContainer> ueDevs; enbDevs = lteHelper->InstallEnbDevice (enbNodes); for (uint32_t i = 0; i < nEnb; i++) { NetDeviceContainer ueDev = lteHelper->InstallUeDevice (ueNodes.at(i)); ueDevs.push_back (ueDev); lteHelper->Attach (ueDev, enbDevs.Get (i)); enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDev, bearer); } BuildingsHelper::MakeMobilityModelConsistent (); Simulator::Stop (Seconds (simTime)); lteHelper->EnableTraces (); Simulator::Run (); /*GtkConfigStore config; config.ConfigureAttributes ();*/ Simulator::Destroy (); return 0; }
// Add a new note to the database qint32 NoteTable::add(qint32 l, Note &t, bool isDirty) { QLOG_DEBUG() << "Adding note: " << QString::fromStdString(t.title); ResourceTable resTable; ConfigStore cs; QSqlQuery query; qint32 position; TagScanner scanner; qint32 lid = l; qint32 notebookLid; query.prepare("Insert into DataStore (lid, key, data) values (:lid, :key, :data)"); if (lid <= 0) lid = cs.incrementLidCounter(); query.bindValue(":lid", lid); query.bindValue(":key", NOTE_GUID); query.bindValue(":data", QString::fromStdString(t.guid)); query.exec(); query.bindValue(":lid", lid); query.bindValue(":key", NOTE_INDEX_NEEDED); query.bindValue(":data", true); query.exec(); if (t.__isset.title) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_TITLE); query.bindValue(":data", QString::fromStdString(t.title.c_str())); query.exec(); } if (t.__isset.content) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_CONTENT); QByteArray b; b.append(QString::fromStdString(t.content).toAscii()); query.bindValue(":data", b); query.exec(); } if (t.__isset.contentHash) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_CONTENT_HASH); query.bindValue(":data", QString::fromStdString(t.contentHash)); query.exec(); } if (t.__isset.contentLength) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_CONTENT_LENGTH); query.bindValue(":data", t.contentLength); query.exec(); } query.bindValue(":lid", lid); query.bindValue(":key", NOTE_UPDATE_SEQUENCE_NUMBER); query.bindValue(":data", t.updateSequenceNum); query.exec(); query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ISDIRTY); query.bindValue(":data", isDirty); query.exec(); if (t.__isset.created) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_CREATED_DATE); query.bindValue(":data", QVariant::fromValue(t.created)); query.exec(); } if (t.__isset.updated) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_UPDATED_DATE); query.bindValue(":data", QVariant::fromValue(t.updated)); query.exec(); } if (t.__isset.deleted) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_DELETED_DATE); query.bindValue(":data", QVariant::fromValue(t.deleted)); query.exec(); } if (t.__isset.active) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ACTIVE); query.bindValue(":data", QVariant::fromValue(t.active)); query.exec(); } if (t.__isset.notebookGuid) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_NOTEBOOK_LID); NotebookTable notebookTable; notebookLid = notebookTable.getLid(QString::fromStdString(t.notebookGuid)); // If not found, we insert one to avoid problems. We'll probably get the real data later if (notebookLid == 0) { notebookLid = cs.incrementLidCounter(); Notebook notebook; notebook.guid = t.notebookGuid; notebook.name = ""; notebook.__isset.guid = true; notebook.__isset.name = true; notebookTable.add(notebookLid, notebook, false, false); } query.bindValue(":data", notebookLid); query.exec(); } for (unsigned int i=0; t.__isset.tagGuids && i<t.tagGuids.size(); i++) { TagTable tagTable; qint32 tagLid = tagTable.getLid(t.tagGuids.at(i)); if (tagLid == 0) { // create a dummy tag to avoid later problems Tag newTag; newTag.guid = t.tagGuids.at(i); newTag.name = ""; newTag.__isset.guid = true; newTag.__isset.name = true; tagLid = cs.incrementLidCounter(); tagTable.add(tagLid, newTag, false, 0); } query.bindValue(":lid", lid); query.bindValue(":key", NOTE_TAG_LID); query.bindValue(":data", tagLid); query.exec(); } for (unsigned int i=0; t.__isset.resources && i<t.resources.size(); i++) { qint32 resLid; Resource *r; r = &t.resources[i]; resLid = resTable.getLid(t.guid,t.resources[i].guid); if (resLid == 0) resLid = cs.incrementLidCounter(); resTable.add(resLid, t.resources[i], isDirty); if (r->__isset.mime) { QString mime = QString::fromStdString(r->mime); if (!mime.startsWith("image/") && mime != "vnd.evernote.ink") { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_HAS_ATTACHMENT); query.bindValue(":data", true); query.exec(); } } } if (t.__isset.attributes) { if (t.attributes.__isset.subjectDate) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_SUBJECT_DATE); query.bindValue(":data", QVariant::fromValue(t.attributes.subjectDate)); query.exec(); } if (t.attributes.__isset.latitude) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_LATITUDE); query.bindValue(":data", QVariant::fromValue(t.attributes.latitude)); query.exec(); } if (t.attributes.__isset.latitude) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_LONGITUDE); query.bindValue(":data", QVariant::fromValue(t.attributes.longitude)); query.exec(); } if (t.attributes.__isset.altitude) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_ALTITUDE); query.bindValue(":data", QVariant::fromValue(t.attributes.altitude)); query.exec(); } if (t.attributes.__isset.author) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_AUTHOR); query.bindValue(":data", QString::fromStdString(t.attributes.author)); query.exec(); } if (t.attributes.__isset.source) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_SOURCE); query.bindValue(":data", QString::fromStdString(t.attributes.source)); query.exec(); } if (t.attributes.__isset.sourceURL) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_SOURCE_URL); query.bindValue(":data", QString::fromStdString(t.attributes.sourceURL)); query.exec(); } if (t.attributes.__isset.sourceApplication) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_SOURCE_APPLICATION); query.bindValue(":data", QString::fromStdString(t.attributes.sourceApplication)); query.exec(); } if (t.attributes.__isset.shareDate) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_SHARE_DATE); query.bindValue(":data",QVariant::fromValue(t.attributes.shareDate)); query.exec(); } if (t.attributes.__isset.placeName) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_PLACE_NAME); query.bindValue(":data", QString::fromStdString(t.attributes.placeName)); query.exec(); } if (t.attributes.__isset.contentClass) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_ATTRIBUTE_CONTENT_CLASS); query.bindValue(":data", QString::fromStdString(t.attributes.contentClass)); query.exec(); } } // No determine some attributes of the note based upon the content // This should probably happen every time a note changes? Or at least something simular: QString content; if (t.__isset.content) content = QString::fromStdString(t.content); else content = ""; position = content.indexOf("<en-crypt"); if (position > 0) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_HAS_ENCRYPT); query.bindValue(":data", true); query.exec(); } position = content.indexOf("<en-todo"); if (position > 0) { position = content.indexOf("<en-todo checked=\"true\""); if (position > 0) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_HAS_TODO_COMPLETED); query.bindValue(":data", true); query.exec(); } position = qMax(content.indexOf("<en-todo checked=\"false\""), content.indexOf("<en-todo>")); if (position > 0) { query.bindValue(":lid", lid); query.bindValue(":key", NOTE_HAS_TODO_UNCOMPLETED); query.bindValue(":data", true); query.exec(); } } updateNoteList(lid, t, isDirty); return lid; }
qint32 NoteTable::duplicateNote(qint32 oldLid) { ConfigStore cs; qint32 newLid = cs.incrementLidCounter(); QSqlQuery query; QString tempTableName = "notecopy" + QString::number(oldLid); query.exec("drop temporary table " +tempTableName); query.prepare("create temporary table " +tempTableName +" as select * from datastore where lid=:oldLid"); query.bindValue(":oldLid", oldLid); query.exec(); query.prepare("Update " +tempTableName +" set lid=:newLid"); query.bindValue(":newLid", newLid); query.exec(); query.exec("insert into datastore select lid, key, data from " +tempTableName); query.exec("drop " +tempTableName); query.prepare("update datastore set data=:data where lid=:lid and key=:key"); query.bindValue(":data", 0); query.bindValue(":lid", newLid); query.bindValue(":key", NOTE_UPDATE_SEQUENCE_NUMBER); query.exec(); Note n; get(n, newLid, false,false); updateNoteList(newLid, n, true); setDirty(newLid, true); // Update all the resources ResourceTable resTable; QList<qint32> lids; resTable.getResourceList(lids, oldLid); for (int i=0; i<lids.size(); i++) { qint32 newResLid = cs.incrementLidCounter(); query.prepare("create temporary table " +tempTableName +" as select * from datastore where lid=:oldLid"); query.bindValue(":oldLid", lids[i]); query.exec(); query.prepare("Update " +tempTableName +" set lid=:newLid"); query.bindValue(":newLid", newResLid); query.exec(); query.exec("insert into datastore select lid, key, data from " +tempTableName); query.exec("drop " +tempTableName); query.prepare("update datastore set data=:data where lid=:lid and key=:key"); query.bindValue(":data", 0); query.bindValue(":lid", newResLid); query.bindValue(":key", RESOURCE_UPDATE_SEQUENCE_NUMBER); query.exec(); query.prepare("update datastore set data=:data where lid=:lid and key=:key"); query.bindValue(":data", 0); query.bindValue(":lid", newResLid); query.bindValue(":key", RESOURCE_NOTE_LID); query.exec(); QStringList filter; QDir resDir(global.fileManager.getDbaDirPath()); filter << QString::number(lids[i])+".*"; QStringList files = resDir.entryList(filter); for (int j=0; j<files.size(); j++) { QFile file(global.fileManager.getDbaDirPath()+files[j]); int pos = files[j].indexOf("."); QString type = files[j].mid(pos); file.open(QIODevice::ReadOnly); file.copy(global.fileManager.getDbaDirPath()+ QString::number(newResLid) +type); file.close(); } } return newLid; }
void SharedNotebookTable::add(qint32 l, SharedNotebook &t, bool isDirty){ isDirty=isDirty; //suppress unused ConfigStore cs; qint32 lid = l; if (lid == 0) lid = cs.incrementLidCounter(); QSqlQuery query; query.prepare("Insert into DataStore (lid, key, data) values (:lid, :key, :data)"); if (t.__isset.email) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_EMAIL); query.bindValue(":data", QString::fromStdString(t.email)); query.exec(); } if (t.__isset.id) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_ID); query.bindValue(":data", QVariant::fromValue(t.id)); query.exec(); } if (t.__isset.notebookGuid) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_NOTEBOOK_GUID); query.bindValue(":data", QString::fromStdString(t.notebookGuid)); query.exec(); } if (t.__isset.notebookModifiable) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_PRIVILEGE); query.bindValue(":data", t.privilege); query.exec(); } if (t.__isset.requireLogin) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_ALLOW_PREVIEW); query.bindValue(":data", t.allowPreview); query.exec(); } if (t.__isset.serviceCreated) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_SERVICE_CREATED); query.bindValue(":data", QVariant::fromValue(t.serviceCreated)); query.exec(); } if (t.__isset.shareKey) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_SHARE_KEY); query.bindValue(":data", QString::fromStdString(t.shareKey)); query.exec(); } if (t.__isset.userId) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_USERID); query.bindValue(":data", t.userId); query.exec(); } if (t.__isset.username) { query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_USERNAME); query.bindValue(":data", QString::fromStdString(t.username)); query.exec(); } }