void FunctionCacheSave(JSON Root) { EXCLUSIVE_ACQUIRE(LockFunctions); // Allocate JSON object array const JSON jsonFunctions = json_array(); const JSON jsonAutoFunctions = json_array(); for(auto & i : functions) { JSON currentFunction = json_object(); json_object_set_new(currentFunction, "module", json_string(i.second.mod)); json_object_set_new(currentFunction, "start", json_hex(i.second.start)); json_object_set_new(currentFunction, "end", json_hex(i.second.end)); if(i.second.manual) json_array_append_new(jsonFunctions, currentFunction); else json_array_append_new(jsonAutoFunctions, currentFunction); } if(json_array_size(jsonFunctions)) json_object_set(Root, "functions", jsonFunctions); if(json_array_size(jsonAutoFunctions)) json_object_set(Root, "autofunctions", jsonAutoFunctions); // Decrease reference count to avoid leaking memory json_decref(jsonFunctions); json_decref(jsonAutoFunctions); }
void CommentCacheSave(JSON Root) { EXCLUSIVE_ACQUIRE(LockComments); const JSON jsonComments = json_array(); const JSON jsonAutoComments = json_array(); // Build the JSON array for(auto & itr : comments) { JSON currentComment = json_object(); json_object_set_new(currentComment, "module", json_string(itr.second.mod)); json_object_set_new(currentComment, "address", json_hex(itr.second.addr)); json_object_set_new(currentComment, "text", json_string(itr.second.text)); if(itr.second.manual) json_array_append_new(jsonComments, currentComment); else json_array_append_new(jsonAutoComments, currentComment); } // Save to the JSON root if(json_array_size(jsonComments)) json_object_set(Root, "comments", jsonComments); if(json_array_size(jsonAutoComments)) json_object_set(Root, "autocomments", jsonAutoComments); json_decref(jsonComments); json_decref(jsonAutoComments); }
void LabelCacheSave(JSON Root) { EXCLUSIVE_ACQUIRE(LockLabels); // Create the sub-root structures in memory const JSON jsonLabels = json_array(); const JSON jsonAutoLabels = json_array(); // Iterator each label for(auto & itr : labels) { JSON jsonLabel = json_object(); json_object_set_new(jsonLabel, "module", json_string(itr.second.mod)); json_object_set_new(jsonLabel, "address", json_hex(itr.second.addr)); json_object_set_new(jsonLabel, "text", json_string(itr.second.text)); // Was the label manually added? if(itr.second.manual) json_array_append_new(jsonLabels, jsonLabel); else json_array_append_new(jsonAutoLabels, jsonLabel); } // Apply the object to the global root if(json_array_size(jsonLabels)) json_object_set(Root, "labels", jsonLabels); if(json_array_size(jsonAutoLabels)) json_object_set(Root, "autolabels", jsonAutoLabels); json_decref(jsonLabels); json_decref(jsonAutoLabels); }
void LoopCacheSave(JSON Root) { EXCLUSIVE_ACQUIRE(LockLoops); // Create the root JSON objects const JSON jsonLoops = json_array(); const JSON jsonAutoLoops = json_array(); // Write all entries for(auto & itr : loops) { const LOOPSINFO & currentLoop = itr.second; JSON currentJson = json_object(); json_object_set_new(currentJson, "module", json_string(currentLoop.mod)); json_object_set_new(currentJson, "start", json_hex(currentLoop.start)); json_object_set_new(currentJson, "end", json_hex(currentLoop.end)); json_object_set_new(currentJson, "depth", json_integer(currentLoop.depth)); json_object_set_new(currentJson, "parent", json_hex(currentLoop.parent)); if(currentLoop.manual) json_array_append_new(jsonLoops, currentJson); else json_array_append_new(jsonAutoLoops, currentJson); } // Append a link to the global root if(json_array_size(jsonLoops)) json_object_set(Root, "loops", jsonLoops); if(json_array_size(jsonAutoLoops)) json_object_set(Root, "autoloops", jsonAutoLoops); // Release memory/references json_decref(jsonLoops); json_decref(jsonAutoLoops); }