struct storage_backend * init_storage_backend(const char * options) { struct stat st; struct storage_backend * store = NULL; //Determine the correct storage backend based on the options string if (strlen(options) == 0) { log_message(STORE_LOGLVL_ERR, "init_storage_backend: Options string was empty"); return NULL; } if (options[0] == '/') { if (stat(options, &st) != 0) { log_message(STORE_LOGLVL_ERR, "init_storage_backend: Failed to stat %s with error: %s", options, strerror(errno)); return NULL; } if (S_ISDIR(st.st_mode)) { log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising file storage backend at: %s", options); store = init_storage_file(options); return store; } else { log_message(STORE_LOGLVL_ERR, "init_storage_backend: %s is not a directory", options, strerror(errno)); return NULL; } } if (strstr(options,"rados://") == options) { log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising rados storage backend at: %s", options); store = init_storage_rados(options); return store; } if (strstr(options,"memcached://") == options) { log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising memcached storage backend at: %s", options); store = init_storage_memcached(options); return store; } if (strstr(options,"ro_http_proxy://") == options) { log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising ro_http_proxy storage backend at: %s", options); store = init_storage_ro_http_proxy(options); return store; } if (strstr(options,"composite:{") == options) { log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising ro_composite storage backend at: %s", options); store = init_storage_ro_composite(options); return store; } log_message(STORE_LOGLVL_ERR, "init_storage_backend: No valid storage backend found for options: %s", options); return store; }
int main(int argc, char **argv) { int c; for (int i=0; i<=MAXZOOM; i++) zoom[i]=0; int zoomset = 0; while (1) { int option_index = 0; static struct option long_options[] = { {"verbose", 0, 0, 'v'}, {"help", 0, 0, 'h'}, {"memcached", 1, 0, 'c'}, {"bbox", 1, 0, 'b'}, {"mode", 1, 0, 'm'}, {"zoom", 1, 0, 'z'}, {"threads", 1, 0, 't'}, {"force", 0, 0, 'f'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "vhb:m:z:c:t:f", long_options, &option_index); if (c == -1) break; switch (c) { case 'v': verbose=1; break; case 'h': usage(); return -1; case 'b': if (!handle_bbox(optarg)) { fprintf(stderr, "invalid bbox argument - must be of the form east,south,west,north\n"); return -1; } break; case 'z': zoomset = 1; if (!handle_zoom(optarg)) { fprintf(stderr, "invalid zoom argument - must be of the form zoom or z0,z1,z2... or z0-z1\n"); return -1; } break; case 'c': sprintf(store_conf, "%s", optarg); if (store_conf == NULL) { return -1; } break; case 't': threadCount=atoi(optarg); if (threadCount <= 0) { fprintf(stderr, "Invalid number of threads, must be at least 1\n"); return 1; } break; case 'm': if (!strcmp(optarg, "glob")) { mode = MODE_GLOB; } else if (!strcmp(optarg, "stat")) { mode = MODE_STAT; fprintf(stderr, "mode=stat not yet implemented\n"); return -1; } else { fprintf(stderr, "mode argument must be either 'glob' or 'stat'\n"); return -1; } break; case 'f': /* -f, --force */ force=1; break; default: fprintf(stderr, "unhandled char '%c'\n", c); break; } } struct ThreadInfo *pThreadInfo = (struct ThreadInfo *)malloc(sizeof(struct ThreadInfo) * threadCount); if (!pThreadInfo) { fprintf(stderr, "Failed to allocate memory\n"); return -1; } for (int i = 0; i < threadCount; ++i) { pThreadInfo[i].isFinished = 0; pThreadInfo[i].id = i; pThreadInfo[i].store = init_storage_memcached(store_conf); pThreadInfo[i].status = THREAD_COMPUTE; pthread_mutex_init(&pThreadInfo[i].mutex, NULL); if (pthread_create(&pThreadInfo[i].pid, NULL, thread, (void *)&pThreadInfo[i]) != 0) { fprintf(stderr, "Failed to start thread\n"); _exit(-1); } } if (!zoomset) for (int i=0; i<=MAXZOOM; i++) zoom[i]=1; if (optind >= argc-1) { usage(); return -1; } source=argv[optind++]; target=argv[optind++]; fprintf(stderr, "Converting tiles from directory %s to directory %s\n", source, target); gettimeofday(&start, NULL); descend(source, 0, pThreadInfo); for (int j = 0; j < threadCount; ++j) { pthread_mutex_lock(&pThreadInfo[j].mutex); pThreadInfo[j].isFinished = 1; pthread_mutex_unlock(&pThreadInfo[j].mutex); } for (int i = 0; i < threadCount; ++i) { pthread_join(pThreadInfo[i].pid, NULL); } gettimeofday(&end, NULL); printf("\nTotal for all tiles converted\n"); printf("Meta tiles converted: "); display_rate(start, end, num_render); printf("Total tiles converted: "); display_rate(start, end, num_render * METATILE * METATILE); for (int i=0; i<threadCount; i++) { if (pThreadInfo[i].store != NULL) { pThreadInfo[i].store->close_storage(pThreadInfo[i].store); } } free(pThreadInfo); return 0; }