================================================================================ PAGE 71 ================================================================================ char*buffer; constintbufferlength =GEVI_MAXACTIONLENGTH; intnumBytesReceived; buffer=newchar[bufferlength]; gevimessage- >WriteASCIIMessage (buffer, bufferlength, numBytesReceived); std::cout <SendMessage (gevimessage); //Don’tforgettodeleteobjects youcreateinsidetheDLL gevimessage- >DeleteObject (); } Receiving ActionMessages ThisexampleshowsyouhowtoreceiveamessagefromGeViSoft. Asaprerequisite, aGeVi- APIClient objectmustalreadybecreatedandconnected totheserver.Furthermore, adata- basenotification callbackfunctionmustbedefined.Thiscallbackfunctionwillbecalledfrom insidetheGeViProcAPI DLLwhenever anotification fromtheserverisreceived. Pseudo code 1.Definethecallback 2.Definethecallback’s handlermethod 3.RegisteryourcallbackwiththeGeViAPIClient connection’s object. 4.Handlethereceivednotifications inyouhandlermethod. C++Example: 1.Define thecallback ================================================================================ PAGE 73 ================================================================================ void__stdcall GeViDatabaseNotificationCB (void*Instance, TServerNotification Notification, void*Params) { if(Instance ==NULL) return; //calling thecallback methodofyourClass object's instance. //Asanexample, CYourClass mightbeCMainWin foranMFCApplication CYourClass* yourClass =(CYourClass*) Instance; yourClass- >DatabaseNotification (Notification, Params); } 2.Define thecallback’s method voidDatabaseNotification (TServerNotification Notification, void*Params) { //Checkifwereceived amessage. Itmightalsobeanother //notification likeachangeofsetuporshutdown oftheserver if(Notification ==NFServer_ NewMessage) { //createthemessage ifpossible //(themessage isfreedagaininthemainthreadcontext) CGeViMessage* gevimessage; TMessageEntry* messageEntry = reinterpret_ cast (Params); intnoOfBytesRead =0; gevimessage =CGeViMessage::ReadBinMessage ( messageEntry- >Buffer, messageEntry- >Length, noOfBytesRead); if(gevimessage) { //Youreceived amessage! Nowyouneedtohandleit. //Thiscanbedonehere. } else ================================================================================ PAGE 74 ================================================================================ { //Message couldnotbecreated. Handletheerrorhere. } } else { //Ifwearehere,wereceived another typeofnotification } } 3.Register yourcallback withtheconnection object. m_APIClient =newGeViAPIClient ( ...); if(m_APIClient) { //connect totheserver TConnectResult ConnectResult = m_APIClient- >Connect (ConnectProgressCB, this); if(ConnectResult ==connectOk) { //Connection established! Nowregister yourcallback! m_APIClient- >SetCBNotification ( GeViDatabaseNotificationCB, this); } } Disconnecting fromaGeViServer Whendisconnecting fromtheserver,youshouldunregister yournotification callbackand deletetheGeViAPIClient object. C++Example: voidDisconnectFromServer () { ================================================================================ PAGE 75 ================================================================================ if(m_APIClient !=NULL) { //Unregister thenotification callback m_APIClient- >SetCBNotification (NULL,NULL); m_APIClient- >Disconnect (); deletem_APIClient; m_APIClient =NULL; } } ================================================================================ PAGE 76 ================================================================================ StateQueries StateQueriesaremessages sentfromtheclienttotheservertogetinformation aboutthe stateoflogicalandphysicalcomponents oftheGeViSoftsystemwellasvirtualressources. Anexampleofsuchinformation wouldbeanenumeration ofallthevideoinputsavailableata GeViServer. Creating StateQueries Youcancreateastatequerybycallingitspredefined constructor. Allthestatequeries’con- structorsarelocatedintheStateQueries header,C++,andPascalfiles. StatequeriescanthenbesentwiththeSendStateQuery ()methodoftheGeViAPIClient class.ThismethodreturnsaCStateAnswer objectwiththeGeViServer’s response. CStateAnswer* StateAnswer =m_APIClient- >SendStateQuery ( GetFirstVideoInputQuery, INFINITE); Thesecondparameter ofthemethodisthetimeoutforaserveranswerinmilliseconds. By sendingINFINITE,youcanpreventthecallfromtimingout. Creating, sending, andreceiving statequeries isimplemented intheSDK’sexam- pleDelphi/CPP_ SimpleClient. Enumeration ofallvideoinputs Pseudo code 1.Createastatequerytogetthefirstvideoinput(classCSQGetFirstVideoInput) 2.Sendthequerytotheserver ================================================================================ PAGE 77 ================================================================================ 3.If theanswerisavalidinputchannelthen 4.REPEAT a)Gettheactualchannel’s  information fromtheanswerandprocessitasneeded(e.g. printitout,storeittoalist) b)CreateastatequerytogetthenextvideoInput(classCSQGetNextVideoInput) c)Sendthequery 5.UNTILthereisnomorevideoinputleft C++Example: voidCMainWin::FillVideoInputsList () { if(m_APIClient ==NULL) return; //Enumerate allavailable videoinputswiththehelpofstatequeries. //Createanewstatequerythatwillreturnthefirstvideoinputchan- nel: CStateQuery* getFirstVideoInputQuery =newCSQGetFirstVideoInput ( true,//showonlyactivechannels true);//showonlyenabled channels if(getFirstVideoInputQuery) { //Sendthequerytotheserver CStateAnswer* stateAnswer =m_APIClient- >SendStateQuery ( getFirstVideoInputQuery, INFINITE); //Timeout //Don'tforgettofreethememoryinsidetheDLL... getFirstVideoInputQuery- >DeleteObject (); if(stateAnswer) { //Iterate through allavailable videoinputchannels ================================================================================ PAGE 78 ================================================================================ while(stateAnswer- >m_AnswerKind !=sak_Nothing) { //Getthechannels info CSAVideoInputInfo* videoInputInfo = reinterpret_ cast (stateAnswer); //createavideoinputdescriptor TVideoInputDescriptor* newVideoInput =new TVideoInputDescriptor (videoInputInfo- >m_GlobalID, videoInputInfo- >m_Name, videoInputInfo- >m_Description, videoInputInfo- >m_HasPTZHead, videoInputInfo- >m_HasVideoSensor, videoInputInfo- >m_HasContrastDetection, videoInputInfo- >m_HasSyncDetection); //Dosomething withthechannel information. Here: //Addthechannel information toa //CListBox lbVideoInputs intnewIndex =lbVideoInputs.AddString ( newVideoInput- >m_Name.c_str()); lbVideoInputs.SetItemDataPtr (newIndex, newVideoInput); //Createaquerytogetthenextinputchannel CStateQuery* getNextVideoInputQuery =new CSQGetNextVideoInput (true,true, videoInputInfo- >m_GlobalID); stateAnswer- >DeleteObject (); stateAnswer =NULL; if(getNextVideoInputQuery) { stateAnswer = m_APIClient- >SendStateQuery ( getNextVideoInputQuery, INFINITE); getNextVideoInputQuery- >DeleteObject (); if(!stateAnswer) break; } else//Nomorevideoinputchannel detected! break; } if(stateAnswer) ================================================================================ PAGE 79 ================================================================================ { stateAnswer- >DeleteObject (); stateAnswer =NULL; } } } } ================================================================================ PAGE 80 ================================================================================ Database Queries (optional) Database queriesallowyoutofetchdatasetsfromtheactionoralarmtableoftheGeViSoft activitydatabase. Alltheactionsthathavebeenreceivedandallthealarmeventsthat occurredarestoredinsidethedatabase. Tospecifyandnarrowdownyourqueryresults,sev- eralfilteroperations areavailableaswell. Togetfamiliar withthepossibilities ofGeViSoft’s database queries, andespe- ciallyitsfiltering options, please havealookattheGeViAPI TestClient’s “Data- baseViewer” and“Database Filter” tabs. Creating Database Queries Youcancreateadatabasequerybycallingitspredefined constructor. Allthedatabaseque- ries’constructors arelocatedintheDatabaseQueries header,C++,andPascalfiles. Database queriescanthenbesentwiththeSendDatabaseQuery ()methodoftheGeVi- APIClient class.ThismethodreturnsaCDataBaseAnswer objectwiththeGeViServer’s response. CDataBaseQuery* geviquery =newCDBQCreateActionQuery (0); CDataBaseAnswer* dbAnswer =m_APIClient- >SendDatabaseQuery (geviquery, INFI- NITE); Thesecondparameter ofthemethodisthetimeoutforaserveranswerinmilliseconds. By sendingINFINITE,youcanpreventthecallfromtimingout. Database QuerySession Handling Actionsendingandstatequeryingdidnotneedanyformofsessionhandling.Thisisdifferent fordatabasequerying.Usuallyyouwanttocollectseveralrecordsthatareconnected in