void EntityManager_Print(FILE *ofp, const char *header, const EntityManager *entityManager) { htab *t = NULL; if (header != NULL) fprintf(ofp, "%s\n", header); // print the header even for NULL items if (entityManager == NULL) { snprintf(errStr, sizeof(errStr), "EntityManager_Print: entityManager must not be NULL"); return; } t = entityManager->Users->Items; if (hfirst(t)) { do { printUser(ofp, "", (void *)hstuff(t)); } while (hnext(t)); } t = entityManager->Groups->Items; if (hfirst(t)) { do { printGroup(ofp, "", (void *)hstuff(t)); } while (hnext(t)); } t = entityManager->Resources->Items; if (hfirst(t)) { do { printResource(ofp, "", (void *)hstuff(t)); } while (hnext(t)); } fprintf(ofp, "\n"); }
// Print resource information include its properties STATIC void fullPrintResource(FILE *ofp, const char *header, const void *u) { const resourceData *entity = NULL; printResource(ofp, header, u); if (u == NULL) return; entity = (const resourceData *)u; printProperties(ofp, entity->PropertiesData); }
void display_all_resources(struct resources *front) { struct resources *ptr; for (ptr = front; ptr != NULL; ptr = ptr->next) { printResource(ptr); } }
//The setup function is called once at startup of the sketch void setup() { // Add your initialization code here // Note : This will initialize Serial port on Arduino at 115200 bauds OIC_LOG_INIT(); OIC_LOG(DEBUG, TAG, ("OCServer is starting...")); // Connect to Ethernet or WiFi network if (ConnectToNetwork() != 0) { Serial.print("Unable to connect to Network"); OIC_LOG(ERROR, TAG, ("Unable to connect to network")); return; } // Initialize the OC Stack in Server mode if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) { OIC_LOG(ERROR, TAG, ("OCStack init error")); return; } // DEBUG PIN pinMode(LED_PIN, OUTPUT); // Button resource OCBaseResourceT *temperatureResource = createResource("/a/temperatureSensor", OIC_DEVICE_SENSOR, OC_RSRVD_INTERFACE_DEFAULT, (OC_DISCOVERABLE | OC_OBSERVABLE | OC_SLOW | OC_ACTIVE), temperatureIOHandler); temperatureResource->name = "LM35 Temperature Sensor"; addType(temperatureResource, OIC_TYPE_TEMPERATURE); // READ only interface addInterface(temperatureResource, OC_RSRVD_INTERFACE_READ); OCIOPort port; port.pin = TEMPERATURE_PIN_IN; port.type = IN; // Setup ADC analogReference(INTERNAL1V1); ResourceData data; data.str = "0.0"; addAttribute(&temperatureResource->attribute, "temperature", data, STRING, &port); printResource(temperatureResource); }
//The setup function is called once at startup of the sketch void setup() { // Add your initialization code here // Note : This will initialize Serial port on Arduino at 115200 bauds OIC_LOG_INIT(); OIC_LOG(DEBUG, TAG, ("OCServer is starting...")); // Connect to Ethernet or WiFi network if (ConnectToNetwork() != 0) { Serial.print("Unable to connect to Network"); OIC_LOG(ERROR, TAG, ("Unable to connect to network")); return; } // Initialize the OC Stack in Server mode if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) { OIC_LOG(ERROR, TAG, ("OCStack init error")); return; } // DEBUG PIN pinMode(LED_PIN, OUTPUT); // Button resource OCBaseResourceT *buttonResource = createResource("/a/button", OIC_DEVICE_BUTTON, OC_RSRVD_INTERFACE_DEFAULT, (OC_DISCOVERABLE | OC_OBSERVABLE | OC_SLOW), buttonIOHandler); buttonResource->name = "Marks Button"; OCIOPort port; port.pin = TEST_BUT_PIN; port.type = IN; ResourceData data; data.b = false; addAttribute(&buttonResource->attribute, "state", data, BOOL, &port); printResource(buttonResource); }
int main(int argc, char **argv) { const char *inputImage = NULL, *outputImage = NULL, *string = NULL, *file = NULL; unsigned long mode = 0, result = 0, id = 0; Elf32_ResType type = ELF_RES_TYPE_UNKNOWN; extern char *optarg; int c; while ((c = getopt(argc, argv, "lhupart:n:s:f:i:o:I:")) != EOF) { switch (c) { case 'h': fprintf(stderr, "Usage: elfres [-u/-p/-l/-a/-r] [-t type] [-s string] [-f file]\n" " [-I id] [-i input img] [-o output img]\n\n" " -p --> print a resource specified by an id.\n" " -u --> update a resource.\n" " -l --> list resources in the specified input file.\n" " -a --> add a resource to the specified input file\n" " and store it in the output file, if specified.\n" " -r --> remove a resource to the specified input file\n" " and store it in the output file, if specified.\n" " the resource is identified by an index (-n).\n"); return 0; case 'l': mode = OPERATION_LIST; break; case 'p': mode = OPERATION_PRINT; break; case 'a': mode = OPERATION_ADD; break; case 'r': mode = OPERATION_REM; break; case 'u': mode = OPERATION_UPDATE; break; case 't': if (!strcasecmp(optarg, "binary")) type = ELF_RES_TYPE_BINARY; else if (!strcasecmp(optarg, "string")) type = ELF_RES_TYPE_STRING; else type = ELF_RES_TYPE_UNKNOWN; break; case 's': string = optarg; break; case 'f': file = optarg; break; case 'I': id = strtoul(optarg, NULL, 10); break; case 'i': inputImage = optarg; break; case 'o': outputImage = optarg; break; default: break; } } if (!inputImage) { fprintf(stderr, "elfres: No input file was specified.\n"); return 0; } if (!outputImage) outputImage = inputImage; switch (mode) { case OPERATION_LIST: result = listResources(inputImage); break; case OPERATION_PRINT: if (!id) fprintf(stderr, "elfres: no identifier was specified (-I).\n"); else result = printResource(inputImage, id); break; case OPERATION_ADD: case OPERATION_UPDATE: if (!id) fprintf(stderr, "elfres: no identifier was specified (-I).\n"); else if (!string && !file) fprintf(stderr, "elfres: no data source was specified (-s/-f).\n"); else result = addResource(mode, inputImage, outputImage, type, id, string, file); break; case OPERATION_REM: if (!id) fprintf(stderr, "elfres: no identifier was specified (-I).\n"); else result = removeResource(inputImage, outputImage, id); break; default: fprintf(stderr, "elfres: unknown mode of operation.\n"); break; } if (!result) fprintf(stderr, "elfres: the operation did not complete successfully.\n"); return result; }