static void _GetData( char *id, SessionData *session, SessionCtrl *ctrl) { ValueStruct *v,*a; int size; if (session == NULL) { return; } if (ctrl->sysdbvals == NULL) { Warning("ctrl->sysdbvals is null"); return; } a = GetRecordItem(ctrl->sysdbvals,"values"); size = ValueArraySize(a); if (ctrl->size >= size) { if (ctrl->size == size) { Warning("GetDataAll SYSDBVALS_SIZE(%d) over",size); } ctrl->size += 1; return; } v = GetArrayItem(a,ctrl->size); if (v != NULL) { CopyValue(v,session->sysdbval); } ctrl->size += 1; }
static void SetMessage( GHashTable *hash, SessionCtrl *ctrl) { ValueStruct *v,*w; ctrl->rc = SESSION_CONTROL_NG; if (ctrl->sysdbval == NULL) { Warning("ctrl->sysdbval is NULL"); return; } v = GetRecordItem(ctrl->sysdbval,"id"); if ((ctrl->session = g_hash_table_lookup(hash,ValueToString(v,NULL))) == NULL) { return; } v = GetRecordItem(ctrl->session->sysdbval,"popup"); w = GetRecordItem(ctrl->sysdbval,"popup"); SetValueString(v,ValueToString(w,NULL),NULL); v = GetRecordItem(ctrl->session->sysdbval,"dialog"); w = GetRecordItem(ctrl->sysdbval,"dialog"); SetValueString(v,ValueToString(w,NULL),NULL); v = GetRecordItem(ctrl->session->sysdbval,"abort"); w = GetRecordItem(ctrl->sysdbval,"abort"); SetValueString(v,ValueToString(w,NULL),NULL); ctrl->rc = SESSION_CONTROL_OK; }
static void _SetMessage( char *id, SessionData *session, SessionCtrl *ctrl) { ValueStruct *v,*w; if (ctrl->sysdbval == NULL) { Warning("ctrl->sysdbval is NULL"); return; } if (session == NULL) { return; } v = GetRecordItem(session->sysdbval,"popup"); w = GetRecordItem(ctrl->sysdbval,"popup"); SetValueString(v,ValueToString(w,NULL),NULL); v = GetRecordItem(session->sysdbval,"dialog"); w = GetRecordItem(ctrl->sysdbval,"dialog"); SetValueString(v,ValueToString(w,NULL),NULL); v = GetRecordItem(session->sysdbval,"abort"); w = GetRecordItem(ctrl->sysdbval,"abort"); SetValueString(v,ValueToString(w,NULL),NULL); }
static VALUE recval_aset(VALUE self, VALUE name, VALUE obj) { value_struct_data *data; ValueStruct *val; Data_Get_Struct(self, value_struct_data, data); val = GetRecordItem(data->value, StringValuePtr(name)); if (val == NULL) rb_raise(rb_eArgError, "no such field: %s", StringValuePtr(name)); set_value(val, obj); return obj; }
static VALUE recval_set_field(VALUE self, VALUE obj) { value_struct_data *data; ValueStruct *val; char *s = rb_id2name(ruby_frame->last_func); VALUE name; name = rb_str_new(s, strlen(s) - 1); Data_Get_Struct(self, value_struct_data, data); val = GetRecordItem(data->value, StringValuePtr(name)); if (val == NULL) rb_raise(rb_eArgError, "no such field: %s", StringValuePtr(name)); set_value(val, obj); return obj; }
static VALUE recval_get_field(VALUE self) { VALUE obj; value_struct_data *data; ValueStruct *val; char *name = rb_id2name(ruby_frame->last_func); Data_Get_Struct(self, value_struct_data, data); if (!NIL_P(obj = rb_hash_aref(data->cache, rb_str_new2(name)))) return obj; val = GetRecordItem(data->value, name); obj = get_value(val); if (CACHEABLE(val)) rb_hash_aset(data->cache, rb_str_new2(name), obj); return obj; }
static void GetData( GHashTable *hash, SessionCtrl *ctrl) { ValueStruct *v; ctrl->rc = SESSION_CONTROL_NG; if (ctrl->sysdbval == NULL) { Warning("ctrl->sysdbval is NULL"); return; } v = GetRecordItem(ctrl->sysdbval,"id"); if ((ctrl->session = g_hash_table_lookup(hash,ValueToString(v,NULL))) == NULL) { return; } if (ctrl->sysdbval != NULL) { CopyValue(ctrl->sysdbval,ctrl->session->sysdbval); } ctrl->rc = SESSION_CONTROL_OK; }
static void SetSysdbval( SessionData *session, ValueStruct *sysdbval) { ValueStruct *v; char buf[128]; v = GetRecordItem(sysdbval,"id"); SetValueString(v,session->hdr->uuid,NULL); v = GetRecordItem(sysdbval,"user"); SetValueString(v,session->hdr->user,NULL); v = GetRecordItem(sysdbval,"host"); SetValueString(v,session->host,NULL); v = GetRecordItem(sysdbval,"agent"); SetValueString(v,session->agent,NULL); v = GetRecordItem(sysdbval,"window"); SetValueString(v,session->hdr->window,NULL); v = GetRecordItem(sysdbval,"widget"); SetValueString(v,session->hdr->widget,NULL); v = GetRecordItem(sysdbval,"event"); SetValueString(v,session->hdr->event,NULL); v = GetRecordItem(sysdbval,"in_process"); SetValueString(v,(session->fInProcess ? "T":"F"),NULL); v = GetRecordItem(sysdbval,"create_time"); _strftime(buf, sizeof(buf), session->create_time.tv_sec); SetValueString(v,buf,NULL); v = GetRecordItem(sysdbval,"access_time"); _strftime(buf, sizeof(buf), session->access_time.tv_sec); SetValueString(v,buf,NULL); v = GetRecordItem(sysdbval,"process_time"); TimevalToString(buf,sizeof(buf),session->process_time); SetValueString(v,buf,NULL); v = GetRecordItem(sysdbval,"total_process_time"); TimevalToString(buf,sizeof(buf),session->total_process_time); SetValueString(v,buf,NULL); v = GetRecordItem(sysdbval,"count"); snprintf(buf,sizeof(buf),"%d",session->count); SetValueString(v,buf,NULL); }
void GameRecord::UpdataRecordView(unsigned sortMethod, unsigned pageOffset) { bool bpageUp = false, bpageDown = false, bpageSmall = false; for (auto item : m_vecRecordNew) { item->m_pSpriteBgItem->setVisible(false); m_vecRecordOld.push_back(item); } m_vecRecordNew.clear(); Size sz = m_btNextPage->getContentSize(); unsigned uAllItem = 0; if (m_uCurPage == g_globalGameRecord.m_uAllPage) { uAllItem = g_globalGameRecord.m_vecRecord[sortMethod].size() - pageOffset; } else { uAllItem = GameRecordPerPage; } unsigned uItemH = 110; //条目高度 + 条目间隙 unsigned uAllItemH = uItemH*uAllItem; float fX = ScrollW / 2, fY = 55; if (m_uCurPage < g_globalGameRecord.m_uAllPage) { uAllItemH += sz.height; bpageDown = true; } if (m_uCurPage > 1) { uAllItemH += sz.height; bpageUp = true; } if (uAllItemH < ScrollH) { fY = ScrollH - uAllItemH + fY; uAllItemH = ScrollH; bpageSmall = true; } double offSet = ScrollH - (int)uAllItemH; fY = uAllItemH; m_ScrollView->setContentOffset(Vec2(0, offSet), false); if (bpageUp) { //当前页大于第一页,创建上一页按钮 fY = fY - sz.height/2; m_btPrePage->setVisible(true); m_btPrePage->setPosition(fX, fY); m_btPrePage->SetHitCB(std::bind(&GameRecord::OnPageTurnUp, this)); m_btPrePage->retain(); fY = fY - uItemH / 2 - sz.height / 2; } else { fY = fY - uItemH / 2 - 5; m_btPrePage->setVisible(false); m_btPrePage->retain(); } /*int count = 0; int onePageNum = 0; for (auto recordItem : g_globalGameRecord.m_vecRecord[sortMethod]) { if (count >= pageOffset && count < pageOffset + GameRecordPerPage) { onePageNum ++; auto item = GetRecordItem(recordItem.m_strID); UpdateRecordItem(item, recordItem); item->m_pSpriteBgItem->setPosition(fX, fY); item->m_pSpriteBgItem->setVisible(true); m_vecRecordNew.push_back(item); fY -= uItemH; } if (onePageNum > 20)break; count ++; }*/ int vecSz = g_globalGameRecord.m_vecRecord[sortMethod].size(); for (int i=0; i<GameRecordPerPage; i++) { if (pageOffset + i >= vecSz)break; auto item = GetRecordItem(g_globalGameRecord.m_vecRecord[sortMethod][pageOffset+i].m_strID); UpdateRecordItem(item, g_globalGameRecord.m_vecRecord[sortMethod][pageOffset+i]); item->m_pSpriteBgItem->setPosition(fX, fY); item->m_pSpriteBgItem->setVisible(true); m_vecRecordNew.push_back(item); fY -= uItemH; } if (bpageDown) { fY = sz.height/2; //当前页小于总页数,创建下一页按钮 m_btNextPage->setVisible(true); m_btNextPage->setPosition(fX, fY); m_btNextPage->SetHitCB(std::bind(&GameRecord::OnPageTurnDown, this)); m_btNextPage->retain(); } else { m_btNextPage->setVisible(false); m_btNextPage->retain(); } m_ScrollView->setContentSize(Size(ScrollW, uAllItemH)); }
int main(int argc, char *argv[]) { ValueStruct *value, *v; size_t size; char *buf; RecParserInit(); value = RecParseValueMem(recdef, NULL); InitializeValue(value); v = GetRecordItem(value, "command"); SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL); v = GetItemLongName(value, "record1[0].col1"); SetValueString(v, "bbbb", NULL); v = GetItemLongName(value, "record1[0].record2.col21"); SetValueString(v, "cccc", NULL); v = GetItemLongName(value, "int1"); SetValueInteger(v, 10); v = GetItemLongName(value, "int2"); SetValueInteger(v, 20); v = GetItemLongName(value, "double1"); SetValueFloat(v, -3.2); fprintf(stderr, "\n---- JSON_PackValue\n"); size = JSON_SizeValue(NULL, value); fprintf(stderr, "size:%ld\n", size); buf = malloc(size + 1); memset(buf, 0, size + 1); JSON_PackValue(NULL, buf, value); fprintf(stderr, "[%s]\nsize:%ld\n", buf, strlen(buf)); fprintf(stderr, "\n---- JSON_UnPackValue 1\n"); JSON_UnPackValue(NULL, buf, value); DumpValueStruct(value); free(buf); fprintf(stderr, "\n---- JSON_UnPackValue 2\n"); JSON_UnPackValue(NULL, "{\"int1\":1000,\"int2\":2000}", value); DumpValueStruct(value); /* ommit */ fprintf(stderr, "\n-------------------\n"); fprintf(stderr, "ommit\n"); fprintf(stderr, "-------------------\n\n"); InitializeValue(value); v = GetRecordItem(value, "command"); SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL); v = GetItemLongName(value, "record1[0].col1"); SetValueString(v, "bbbb", NULL); v = GetItemLongName(value, "record1[0].record2.col21"); SetValueString(v, "cccc", NULL); v = GetItemLongName(value, "int1"); SetValueInteger(v, 10); v = GetItemLongName(value, "int2"); SetValueInteger(v, 20); v = GetItemLongName(value, "record3[1].record4[1].vc41"); SetValueString(v, "vc41", NULL); fprintf(stderr, "\n---- JSON_PackValueOmmit\n"); size = JSON_SizeValueOmmit(NULL, value); fprintf(stderr, "size:%ld\n", size); buf = malloc(size + 1); memset(buf, 0, size + 1); JSON_PackValueOmmit(NULL, buf, value); fprintf(stderr, "size:%ld [%s]\n", strlen(buf), buf); free(buf); fprintf(stderr, "\n---- JSON_UnPackValueOmmit\n"); JSON_UnPackValueOmmit(NULL, "{\"int1\":1000,\"int2\":2000}", value); DumpValueStruct(value); fprintf(stderr, "\n---- JSON_UnPackValueOmmit 2\n"); JSON_UnPackValueOmmit( NULL, "{\"int1\":1234,\"int2\":5678,\"bool1\":false,\"double1\":3.141592}", value); DumpValueStruct(value); fprintf(stderr, "\n---- JSON_UnPackValueOmmit 3\n"); JSON_UnPackValueOmmit( NULL, "{\"int1\":1000,\"command\":\"moge\",\"record1\":[{\"col1\":\"muge\"," "\"record2\":{\"col21\":\"gage\"}},{},{\"col2\":\"nuge\"}],\"record3\":[{" "},{\"record4\":[{},{\"vc41\":\"vc41\"}]}]}", value); DumpValueStruct(value); InitializeValue(value); fprintf(stderr, "\n---- test\n"); JSON_UnPackValueOmmit(NULL, "{\"int1\":10,\"int0\":[0,1,2,3,0,5,0,6],\"bool1\":" "false,\"arg1\":\"hogehoge\"}", value); size = JSON_SizeValueOmmit(NULL, value); fprintf(stderr, "size:%ld\n", size); buf = malloc(size); memset(buf, 0, size); JSON_PackValueOmmit(NULL, buf, value); fprintf(stderr, "size:%d %s\n", (int)strlen(buf), buf); free(buf); fprintf(stderr, "\n\n\n\n\n\n---- JSON_PackValueOmmitString\n"); InitializeValue(value); v = GetRecordItem(value, "command"); SetValueString(v, "a\"a\\a/a\ba\fa\na\ra\ta", NULL); v = GetItemLongName(value, "record1[0].col1"); SetValueString(v, "bbbb", NULL); #if 0 v = GetItemLongName(value,"record1[0].record2.col21"); SetValueString(v,"cccc",NULL); #endif v = GetItemLongName(value, "int1"); SetValueInteger(v, 10); v = GetItemLongName(value, "int2"); SetValueInteger(v, 20); v = GetItemLongName(value, "record3[1].record4[1].vc41"); SetValueString(v, "vc41", NULL); DumpValueStruct(value); size = JSON_SizeValueOmmitString(NULL, value); fprintf(stderr, "size:%ld\n", size); buf = malloc(size + 1); memset(buf, 0, size + 1); JSON_PackValueOmmitString(NULL, buf, value); fprintf(stderr, "size:%ld [%s]\n", strlen(buf), buf); free(buf); return 0; }