Advertisement
Guest User

fpserv.cpp

a guest
Jun 5th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <iostream>
  5.  
  6. #include <servio.h>
  7.  
  8. #include "fpserv_async.h"
  9.  
  10. int main(int argc, char** argv) {
  11.   if (sio_open(argc, argv, "FPSERV", "2.0", "") < 0)
  12.     exit(10);
  13.   sio_write(SIO_DATA, "SYS-ACCEPT\tFP-");
  14.  
  15.   std::string str;
  16.  
  17.   FPReader fp;
  18.   fp.ChangeState(IDENTIFYING);
  19.  
  20.   struct timeval handle_fp_timeout;
  21.   handle_fp_timeout.tv_sec = 0;
  22.   handle_fp_timeout.tv_usec = 100*1000;
  23.  
  24.   int ret_val;
  25.   while (true) {
  26.     // Poll the fingerprint reader
  27.     fp_handle_events_timeout(&handle_fp_timeout);
  28.     fp.UpdateState();
  29.  
  30.     // Poll the bus and handle results
  31.     str = "";
  32.     ret_val = sio_read(str, 0);
  33.  
  34.     if(ret_val > 0) {
  35.       std::string command = sio_field(str, 0);
  36.       std::string userid = sio_field(str, 1);
  37.  
  38.       if(command == "FP-LEARN-START"){
  39.         fp.SetUsername(userid);
  40.         fp.ChangeState(ENROLLING);
  41.       }
  42.       else if(command == "FP-LEARN-STOP"){
  43.         fp.SetUsername("not-a-user:identifying-mode");
  44.         fp.ChangeState(IDENTIFYING);
  45.       }
  46.       else{
  47.         std::cout << "Message received: " << str;
  48.         std::cout << " arg1: " << command << " arg2: " << userid << std::endl;
  49.       }
  50.     }
  51.   }
  52.   sio_close(-1, "NewFP server going down");
  53.  
  54.   return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement