bool M2MLWClient::create_object(const char *name, bool new_instance, uint8_t object_operation, uint8_t object_instance_operation, uint16_t object_instance_id, bool object_observable, bool object_instance_observable) { bool success = false; M2MObjectInstance *inst = NULL; if(!_object) { _object = M2MInterfaceFactory::create_object(name); if(_object) { _object->set_operation(int_to_operation(object_operation)); _object->set_observable(object_observable); inst = _object->create_object_instance(object_instance_id); if(inst) { success = true; inst->set_operation(int_to_operation(object_instance_operation)); inst->set_observable(object_instance_observable); } } } else { if(new_instance) { inst = _object->create_object_instance(object_instance_id); if(inst) { success = true; inst->set_operation(int_to_operation(object_instance_operation)); inst->set_observable(object_instance_observable); } } } return success; }
bool M2MLWClient::create_dynamic_resource_instance_string(const char *name, bool observable, bool multiple_instance, uint16_t object_instance, uint16_t resource_instance, uint8_t resource_instance_operation) { bool success = false; String name_string; if(name) { name_string += name; } if(_object) { M2MObjectInstance *inst = _object->object_instance(object_instance); if(inst) { M2MResourceInstance *res = inst->create_dynamic_resource_instance(name,"resource", M2MResourceInstance::STRING, observable, resource_instance); if( res) { success = true; res->set_operation(int_to_operation(resource_instance_operation)); } } } return success; }
int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s program [outfile]\n", argv[0]); exit(ERR_MISSING_ARGUMENTS); } char* input_filename = argv[1]; char* output_filename = "output.uma"; if (argc > 2) output_filename = argv[2]; FILE* input_file = fopen(input_filename, "r"); if (input_file == NULL) { fprintf(stderr, "FATAL: Can't open input file: %s\n", input_filename); exit(ERR_INVALID_INPUT_FILE); } fseek(input_file, 0, SEEK_END); size_t fsize = ftell(input_file); fseek(input_file, 0, SEEK_SET); if (fsize % sizeof(uint32_t) != 0) { fprintf(stderr, "FATAL: Input file's size seems invalid: %zu bytes\n", fsize); exit(ERR_INVALID_INPUT_FILE); } FILE* output_file = fopen(output_filename, "wb"); if (output_file == NULL) { fprintf(stderr, "FATAL: Can't open output file: %s\n", output_filename); exit(ERR_INVALID_OUTPUT_FILE); } Operation op; uint32_t value; size_t i; for(i = 0; i < fsize; i += sizeof(uint32_t)) { if (fread(&value, sizeof(uint32_t), 1, input_file) != 1) { fprintf(stderr, "FATAL: error reading input file %s\n", input_filename); exit(ERR_INVALID_INPUT_FILE); } value = __bswap_32(value); int_to_operation(value, &op); write_source_code(&op, output_file); } fclose(output_file); fclose(input_file); }