int main() { printf("[LPMTd] :: Linux Power Management Tool v1.0\n"); signal(SIGTERM, signal_term); if(LoadConfig(CONFIG_FILE_PATH) || UPowerConnect() || FetchBacklightInfo() || FetchCpuInfo() || UpdatePowerState() || SetBacklight() || SetHDD_APM() || SetCpuFreq()) { printf("[LPMTd] :: Exit status (-1)\n"); return -1; } int new_pstate = WaitUPowerStateChange(); while(new_pstate >= 0) { if(new_pstate != GetPowerState()) { SetPowerState(new_pstate); if(SetBacklight() || SetHDD_APM() || SetCpuFreq()) { printf("[LPMTd] :: Exit status (-1)\n"); return -1; } } new_pstate = WaitUPowerStateChange(); } UPowerDisconnect(); ClearConfig(); printf("[LPMTd] :: Exit status (0)\n"); return 0; }
FConfigFile &FConfigFile::operator = (const FConfigFile &other) { FConfigSection *fromsection, *tosection; FConfigEntry *fromentry; ClearConfig (); fromsection = other.Sections; while (fromsection != NULL) { fromentry = fromsection->RootEntry; tosection = NewConfigSection (fromsection->Name); while (fromentry != NULL) { NewConfigEntry (tosection, fromentry->Key, fromentry->Value); fromentry = fromentry->Next; } fromsection = fromsection->Next; } return *this; }
/* * Import data into GPDB. * invoked by GPDB, be careful with C++ exceptions. */ Datum s3_import(PG_FUNCTION_ARGS) { S3ExtBase *myData; char *data; int data_len; size_t nread = 0; /* Must be called via the external table format manager */ if (!CALLED_AS_EXTPROTOCOL(fcinfo)) elog(ERROR, "extprotocol_import: not called by external protocol manager"); /* Get our internal description of the protocol */ myData = (S3ExtBase *)EXTPROTOCOL_GET_USER_CTX(fcinfo); if (EXTPROTOCOL_IS_LAST_CALL(fcinfo)) { if (myData) { thread_cleanup(); if (!myData->Destroy()) { ereport(ERROR, (0, errmsg("Failed to cleanup S3 extention"))); } delete myData; } /* * Cleanup function for the XML library. */ xmlCleanupParser(); PG_RETURN_INT32(0); } if (myData == NULL) { /* first call. do any desired init */ curl_global_init(CURL_GLOBAL_ALL); thread_setup(); const char *p_name = "s3"; char *url_with_options = EXTPROTOCOL_GET_URL(fcinfo); char *url = truncate_options(url_with_options); char *config_path = get_opt_s3(url_with_options, "config"); if (!config_path) { // no config path in url, use default value // data_folder/gpseg0/s3/s3.conf config_path = strdup("s3/s3.conf"); } bool result = InitConfig(config_path, ""); if (!result) { free(config_path); ereport(ERROR, (0, errmsg("Can't find config file, please check"))); } else { ClearConfig(); free(config_path); } InitLog(); if (s3ext_accessid == "") { ereport(ERROR, (0, errmsg("ERROR: access id is empty"))); } if (s3ext_secret == "") { ereport(ERROR, (0, errmsg("ERROR: secret is empty"))); } if ((s3ext_segnum == -1) || (s3ext_segid == -1)) { ereport(ERROR, (0, errmsg("ERROR: segment id is invalid"))); } myData = CreateExtWrapper(url); if (!myData || !myData->Init(s3ext_segid, s3ext_segnum, s3ext_chunksize)) { if (myData) delete myData; ereport(ERROR, (0, errmsg("Failed to init S3 extension, segid = " "%d, segnum = %d, please check your " "configurations and net connection", s3ext_segid, s3ext_segnum))); } EXTPROTOCOL_SET_USER_CTX(fcinfo, myData); free(url); } /* ======================================================================= * DO THE IMPORT * ======================================================================= */ data = EXTPROTOCOL_GET_DATABUF(fcinfo); data_len = EXTPROTOCOL_GET_DATALEN(fcinfo); uint64_t readlen = 0; if (data_len > 0) { readlen = data_len; if (!myData->TransferData(data, readlen)) ereport(ERROR, (0, errmsg("s3_import: could not read data"))); nread = (size_t)readlen; // S3DEBUG("read %d data from S3", nread); } PG_RETURN_INT32((int)nread); }
void EditorConfig::ParseConfig(const FilePath &filePath) { ClearConfig(); YamlParser *parser = YamlParser::Create(filePath); if(parser) { YamlNode *rootNode = parser->GetRootNode(); if(rootNode) { const Vector<YamlNode*> &yamlNodes = rootNode->AsVector(); int32 propertiesCount = yamlNodes.size(); for(int32 i = 0; i < propertiesCount; ++i) { YamlNode *propertyNode = yamlNodes[i]; if(propertyNode) { const YamlNode *nameNode = propertyNode->Get("name"); const YamlNode *typeNode = propertyNode->Get("type"); const YamlNode *defaultNode = propertyNode->Get("default"); if(nameNode && typeNode) { const String &nameStr = nameNode->AsString(); const String &typeStr = typeNode->AsString(); int32 type = ParseType(typeStr); if(type) { bool isOk = true; for(uint32 n = 0; n < propertyNames.size(); ++n) { if(propertyNames[n] == nameStr) { isOk = false; Logger::Error("EditorConfig::ParseConfig %s ERROR property %d property %s already exists", filePath.GetAbsolutePathname().c_str(), i, nameStr.c_str()); break; } } if(isOk) { properties[nameStr] = new PropertyDescription(); properties[nameStr]->name = nameStr; properties[nameStr]->type = type; switch(type) { case PT_BOOL: { bool defaultValue = false; if(defaultNode) { defaultValue = defaultNode->AsBool(); } properties[nameStr]->defaultValue.SetBool(defaultValue); } break; case PT_INT: { int32 defaultValue = 0; if(defaultNode) { defaultValue = defaultNode->AsInt(); } properties[nameStr]->defaultValue.SetInt32(defaultValue); } break; case PT_STRING: { String defaultValue; if(defaultNode) { defaultValue = defaultNode->AsString(); } properties[nameStr]->defaultValue.SetString(defaultValue); } break; case PT_FLOAT: { float32 defaultValue = 0.0f; if(defaultNode) { defaultValue = defaultNode->AsFloat(); } properties[nameStr]->defaultValue.SetFloat(defaultValue); } break; case PT_COMBOBOX: { int32 defaultValue = 0; if(defaultNode) { defaultValue = defaultNode->AsInt(); } properties[nameStr]->defaultValue.SetInt32(defaultValue); const YamlNode *comboNode = propertyNode->Get("list"); if(comboNode) { const Vector<YamlNode*> &comboValueNodes = comboNode->AsVector(); int32 comboValuesCount = comboValueNodes.size(); for(int32 i = 0; i < comboValuesCount; ++i) { properties[nameStr]->comboValues.push_back(comboValueNodes[i]->AsString()); } } } break; case PT_COLOR_LIST: { int32 defaultValue = 0; if(defaultNode) { defaultValue = defaultNode->AsInt(); } properties[nameStr]->defaultValue.SetInt32(defaultValue); const YamlNode *colorListNode = propertyNode->Get("list"); if(colorListNode) { const Vector<YamlNode*> &colorListNodes = colorListNode->AsVector(); int32 colorListValuesCount = colorListNodes.size(); for(int32 i = 0; i < colorListValuesCount; ++i) { const YamlNode* colorNode = colorListNodes[i]; if(!colorNode || colorNode->GetCount() != 4) continue; Color color(colorNode->Get(0)->AsFloat()/255.f, colorNode->Get(1)->AsFloat()/255.f, colorNode->Get(2)->AsFloat()/255.f, colorNode->Get(3)->AsFloat()/255.f); properties[nameStr]->colorListValues.push_back(color); } } } break; } propertyNames.push_back(nameStr); } //isOk } else { Logger::Error("EditorConfig::ParseConfig %s ERROR property %d unknown type %s", filePath.GetAbsolutePathname().c_str(), i, typeStr.c_str()); } } else { Logger::Error("EditorConfig::ParseConfig %s ERROR property %d type or name is missing", filePath.GetAbsolutePathname().c_str(), i); } } else { Logger::Error("EditorConfig::ParseConfig %s ERROR property %d is missing", filePath.GetAbsolutePathname().c_str(), i); } } } // else file is empty - ok, no custom properties parser->Release(); } // else file not found - ok, no custom properties }
EditorConfig::~EditorConfig() { ClearConfig(); }
static void signal_term(int s) { UPowerDisconnect(); ClearConfig(); printf("[LPMTd] :: Process terminated by signal 15\n"); exit(0); }
bool FConfigFile::ReadConfig (void *file) { char readbuf[READBUFFERSIZE]; FConfigSection *section = NULL; ClearConfig (); while (ReadLine (readbuf, READBUFFERSIZE, file) != NULL) { char *start = readbuf; char *equalpt; char *endpt; // Remove white space at start of line while (*start && *start <= ' ') { start++; } // Remove comment lines if (*start == '#' || (start[0] == '/' && start[1] == '/')) { continue; } // Remove white space at end of line endpt = start + strlen (start) - 1; while (endpt > start && *endpt <= ' ') { endpt--; } endpt[1] = 0; if (endpt <= start) continue; // Nothing here if (*start == '[') { // Section header if (*endpt == ']') *endpt = 0; section = NewConfigSection (start+1); } else if (section == NULL) { return false; } else { // Should be key=value equalpt = strchr (start, '='); if (equalpt != NULL && equalpt > start) { // Remove white space in front of = char *whiteprobe = equalpt - 1; while (whiteprobe > start && isspace(*whiteprobe)) { whiteprobe--; } whiteprobe[1] = 0; // Remove white space after = whiteprobe = equalpt + 1; while (*whiteprobe && isspace(*whiteprobe)) { whiteprobe++; } *(whiteprobe - 1) = 0; NewConfigEntry (section, start, whiteprobe); } } } return true; }