void processCallRequest(LineServerClient *client, char *path, GString *response) { logInfo("Processing rpc call for path: %s", path); // TODO: Figure out if stores can be parsed as a stream. For now, reconstruct // serialized store string from the lines and parse the whole thing at once. GString *serialized_request_store = g_string_new(""); for (int i = 1; i < client->lines->len; ++i) { char *line = g_ptr_array_index(client->lines, i); g_string_append_printf(serialized_request_store, "%s\n", line); } Store *request_store = parseStoreString(serialized_request_store->str); g_string_free(serialized_request_store, true); Store *response_store = callRpc(path, request_store); freeStore(request_store); if (response_store == NULL) { g_string_append(response, "Failed to execute rpc\n"); } else { GString *serialized_response_store = writeStoreGString(response_store); g_string_append_printf(response, "%s\n", serialized_response_store->str); g_string_free(serialized_response_store, true); freeStore(response_store); } }
void destroyRpcService(RpcService *rpc_service) { free(rpc_service->path); if (rpc_service->request_schema != NULL) { freeStore(rpc_service->request_schema); } if (rpc_service->response_schema != NULL) { freeStore(rpc_service->response_schema); } free(rpc_service); }
/** * freeStoreMA */ void freeStoreMA(StoreMA storeMA) { freeStore(storeMA->s); free(storeMA->t); free(storeMA->i); free(storeMA->indextemp); }//freeStoreMA
API bool deleteStorePath(Store *store, char *path) { bool result = false; GPtrArray *array = splitStorePath(path); char **parts = (char **) array->pdata; char *key = parts[array->len - 1]; parts[array->len - 1] = NULL; // cut off last element char *parentpath = g_strjoinv("/", parts); Store *parent = getStorePath(store, "%s", parentpath); int i; void *value; if(parent != NULL) { switch(parent->type) { case STORE_ARRAY: result = g_hash_table_remove(parent->content.array, key); // The hash table frees the removed value automatically break; case STORE_LIST: i = atoi(key); value = g_queue_pop_nth(parent->content.list, i); if(value != NULL) { freeStore(value); result = true; } else { result = false; } break; default: // cannot delete inside a leaf value result = false; break; } } else { result = false; } // Cleanup free(parentpath); free(key); for(i = 0; i < array->len - 1; i++) { free(parts[i]); } g_ptr_array_free(array, TRUE); return result; }
API Store *callRpc(char *path, Store *request) { logInfo("Calling rpc %s", path); RpcService *service = g_hash_table_lookup(service_map, path); if (service == NULL) { logWarning("Failed to call rpc because path %s is not bound", path); return NULL; } if (service->request_schema != NULL && !validateStoreByStoreSchema(request, service->request_schema)) { logWarning("Request store validation failed"); return NULL; } Store *response = service->implementation(request); if (service->response_schema != NULL && !validateStoreByStoreSchema(response, service->response_schema)) { logWarning("Response store validation failed"); freeStore(response); return NULL; } return response; }
API OpenGLLodMap *createOpenGLLodMapFromStore(Store *storeConfig) { Store *store = cloneStore(storeConfig); OpenGLLodMapDataSource *source = createOpenGLLodMapDataSourceFromStore(store); if(source == NULL) { logError("Failed to create LOD map from store: Failed to create LOD map data source!"); freeStore(store); return NULL; } Store *paramBaseRange = getStorePath(store, "lodmap/baseRange"); if(paramBaseRange == NULL || !(paramBaseRange->type == STORE_INTEGER || paramBaseRange->type == STORE_FLOAT_NUMBER)) { logError("Failed to create LOD map from store: Required config float value 'lodmap/baseRange' not found!"); freeStore(store); return NULL; } double baseRange = paramBaseRange->type == STORE_FLOAT_NUMBER ? paramBaseRange->content.float_number : paramBaseRange->content.integer; Store *paramViewingDistance = getStorePath(store, "lodmap/viewingDistance"); if(paramViewingDistance == NULL || paramViewingDistance->type != STORE_INTEGER) { logError("Failed to create LOD map from store: Required config integer value 'lodmap/viewingDistance' not found!"); freeStore(store); return NULL; } int viewingDistance = paramViewingDistance->content.integer; OpenGLLodMap *lodmap = createOpenGLLodMap(source, baseRange, viewingDistance); if(lodmap == NULL) { freeOpenGLLodMapDataSource(source); freeStore(store); return NULL; } if(getStorePath(store, "lodmap/quadtree") != NULL) { Store *paramRootX; int rootX; if((paramRootX = getStorePath(store, "lodmap/quadtree/rootX")) == NULL || paramRootX->type != STORE_INTEGER) { logWarning("LOD map config integer value 'lodmap/quadtree/rootX' not found, using default value of '0'"); rootX = 0; } else { rootX = paramRootX->content.integer; } Store *paramRootY; int rootY; if((paramRootY = getStorePath(store, "lodmap/quadtree/rootY")) == NULL || paramRootY->type != STORE_INTEGER) { logWarning("LOD map config integer value 'lodmap/quadtree/rootY' not found, using default value of '0'"); rootY = 0; } else { rootY = paramRootY->content.integer; } Store *paramRootLevel; int rootLevel; if((paramRootLevel = getStorePath(store, "lodmap/quadtree/rootLevel")) == NULL || paramRootLevel->type != STORE_INTEGER) { logWarning("LOD map config integer value 'lodmap/quadtree/rootLevel' not found, using default value of '0'"); rootLevel = 0; } else { rootLevel = paramRootLevel->content.integer; } reshapeQuadtree(lodmap->quadtree, rootX, rootY, rootLevel); } freeStore(store); return lodmap; }