static void apteryx__set (Apteryx__Server_Service *service, const Apteryx__Set *set, Apteryx__OKResult_Closure closure, void *closure_data) { Apteryx__OKResult result = APTERYX__OKRESULT__INIT; const char *path = NULL; const char *value = NULL; result.result = 0; int validation_result = 0; int validation_lock = 0; int proxy_result = 0; bool db_result = false; int i; /* Check parameters */ if (set == NULL || set->n_sets == 0 || set->sets == NULL) { ERROR ("SET: Invalid parameters.\n"); result.result = -EINVAL; closure (&result, closure_data); INC_COUNTER (counters.set_invalid); return; } INC_COUNTER (counters.set); /* Debug */ for (i=0; apteryx_debug && i<set->n_sets; i++) { DEBUG ("SET: %s = %s\n", set->sets[i]->path, set->sets[i]->value); } /* Proxy first */ for (i=0; i<set->n_sets; i++) { path = set->sets[i]->path; value = set->sets[i]->value; if (value && value[0] == '\0') value = NULL; proxy_result = proxy_set (path, value, set->ts); if (proxy_result == 0) { /* Result success */ DEBUG ("SET: %s = %s proxied\n", path, value); /* Mark the set as processed */ notify_watchers (set->sets[i]->path); free (set->sets[i]->path); set->sets[i]->path = NULL; } else if (proxy_result < 0) { result.result = proxy_result; goto exit; } } /* Validate */ for (i=0; i<set->n_sets; i++) { path = set->sets[i]->path; if (!path) continue; value = set->sets[i]->value; if (value && value[0] == '\0') value = NULL; /* Validate new data */ validation_result = validate_set (path, value); if (validation_result != 0) validation_lock++; if (validation_result < 0) { DEBUG ("SET: %s = %s refused by validate\n", path, value); result.result = validation_result; goto exit; } } /* Set in the database */ pthread_rwlock_wrlock (&db_lock); for (i=0; i<set->n_sets; i++) { path = set->sets[i]->path; if (!path) continue; value = set->sets[i]->value; if (value && value[0] == '\0') value = NULL; /* Add/Delete to/from database */ if (value) db_result = db_add_no_lock (path, (unsigned char*)value, strlen (value) + 1, set->ts); else db_result = db_delete_no_lock (path, set->ts); if (!db_result) { DEBUG ("SET: %s = %s refused by DB\n", path, value); result.result = -EBUSY; pthread_rwlock_unlock (&db_lock); goto exit; } } pthread_rwlock_unlock (&db_lock); /* Set succeeded */ result.result = 0; exit: /* Return result and notify watchers */ if (validation_result >= 0 && result.result == 0) { /* Notify watchers */ for (i=0; i<set->n_sets; i++) { if (set->sets[i]->path) notify_watchers (set->sets[i]->path); } } /* Return result */ closure (&result, closure_data); /* Release validation lock - this is a sensitive value */ while (validation_lock) { DEBUG("SET: unlocking mutex\n"); pthread_mutex_unlock (&validating); validation_lock--; } return; }
MRESULT CreInstDlg::wmCommand(HM12){ USE_HM12; USHORT command; char typename[MAXNAMELENGTH]=""; char propname[MAXNAMELENGTH]=""; char newvalue[MAXNAMELENGTH]=""; int index,dbtype,oktype,i; ODB_INT intval; ODB_REAL realval; ODB_SET coll; object *obj,*o; command=SHORT1FROMMP( mp1 ) ; switch(command) { case DID_OK: //ok button pressed. Create object index=WinQueryLboxSelectedItem(hwndlbtypes); WinQueryLboxItemText(hwndlbtypes,index,typename,MAXNAMELENGTH); if (strlen(typename)<1) { //type not specified WinMessageBox(HWND_DESKTOP,hwndOwner,(PCH) "A type must be spec.", (PCH)"Alert",0,MB_NOICON|MB_OK); break; } else { obj=odb.create_instance(typename); if (obj==NULL) { //object could not be created, possibly because //extentless type selectd WinMessageBox(HWND_DESKTOP,hwndOwner,(PCH) "Could not create object", (PCH)"Alert",0,MB_NOICON|MB_OK); break; }; i=WinQueryLboxCount(hwndassignedprop); i--; while(i>=0){ //check that the data for each prop is ok //and set the properies for the object WinQueryLboxItemText(hwndassignedprop,i,propname,MAXNAMELENGTH); WinQueryLboxItemText(hwndassignedprop,i,propname,MAXNAMELENGTH); WinQueryLboxItemText(hwndpropval,i,newvalue,MAXNAMELENGTH); dbtype=odb.getpropertytype(typename,propname); if (dbtype==_INT_) { validate_integer(newvalue,intval); (*obj).setproperty_value(propname,intval); }; if (dbtype==_OTHER_) { validate_integer(newvalue,intval); o=odb.getobjectwithoid("Usertypes",intval); (*obj).setproperty_value(propname,o); }; if (dbtype==_REAL_) { validate_real(newvalue,realval); (*obj).setproperty_value(propname,realval); }; if (dbtype==_COLLECTION_){ coll=new collection(_OTHER_); if (validate_set(newvalue,&odb,coll)<0) (*coll).~collection(); (*obj).setproperty_value(propname,coll); }; if (dbtype==_INT_COLLECTION_){ coll=new collection(_INT_); if (validate_set(newvalue,&odb,coll)<0) (*coll).~collection(); (*obj).setproperty_value(propname,coll); }; if (dbtype==_REAL_COLLECTION_){ coll=new collection(_REAL_); if (validate_set(newvalue,&odb,coll)<0) (*coll).~collection(); (*obj).setproperty_value(propname,coll); }; if (dbtype==_CHAR_COLLECTION_){ coll=new collection(_CHAR_); if (validate_set(newvalue,&odb,coll)<0) (*coll).~collection(); (*obj).setproperty_value(propname,coll); }; if (dbtype==_CHAR_) (*obj).setproperty_value(propname,newvalue); i--; }; //end while all properties set. //deleta all unassigned praps (*this).clearlbox(hwndassignedprop); clearlbox(hwndpropval); clearlbox(hwndlbprops); WinSetWindowText(hwndviewval,(PSZ)""); populate_props(hwndlbprops,typename, odb); noassignedprops=0; //no assigned properties anymore WinMessageBox(HWND_DESKTOP,hwndOwner,(PCH) "Instance created.", (PCH)"Success",0,MB_NOICON|MB_OK); }; //else //create the object and set properties return (MRESULT) FALSE; //break; case DID_CANCEL: //quit this window if(WinMessageBox(HWND_DESKTOP,hwndOwner,(PCH) "Quit this window?", (PCH)"Sanity Check",0, MB_NOICON|MB_OKCANCEL)==MBID_OK) WinDismissDlg( hwnd, TRUE ); // Removes the dialog box return (MRESULT) FALSE; case PB_SET: //assign property a value. The prop is moved to assignedprops //and value is validated and moved to hidden listbox index=WinQueryLboxSelectedItem(hwndlbtypes); //typename WinQueryLboxItemText(hwndlbtypes,index,typename,MAXNAMELENGTH); index=WinQueryLboxSelectedItem(hwndlbprops); //propname WinQueryLboxItemText(hwndlbprops,index,propname,MAXNAMELENGTH); WinQueryWindowText(hwndnewvalue,MAXNAMELENGTH,newvalue); dbtype=odb.getpropertytype(typename,propname); if (dbtype==_INT_) oktype=validate_integer(newvalue,intval); if (dbtype==_OTHER_){ oktype=validate_integer(newvalue,intval); if (oktype!=0) { //check that there is an object with the oid obj=odb.getobjectwithoid("Usertypes",intval); if (obj==NULL) oktype=0; } }; if (dbtype==_REAL_) oktype=validate_real(newvalue,realval); if (dbtype==_CHAR_) oktype=1; if ((strlen(newvalue)>0)&&(strlen(propname)>0)&&(oktype!=0)){ //move assigned prop from prop cmb box to assigned props WinInsertLboxItem(hwndassignedprop,noassignedprops,(PSZ)propname); WinInsertLboxItem(hwndpropval,noassignedprops,(PSZ)newvalue); noassignedprops++; WinDeleteLboxItem(hwndlbprops,index); WinSetWindowText(hwnddatatype,(PSZ)""); WinSetWindowText(hwndnewvalue,(PSZ)""); } else WinMessageBox(HWND_DESKTOP,hwndOwner,(PCH) "Missing or erroneous data", (PCH)"Alert",0,MB_OKCANCEL); break; default: return WinDefDlgProc( hwnd, msg, mp1, mp2 ); }