rpc procedure (query function)

 u_char _sample_cmd_proc(u_char* query, u_char query_len, void* arg,
                         u_char* result, u_char* result_len)
 {
     // fill result with RPC_MAX_RESULT_LENGTH bytes
     result[0] = query[0];
     switch(query[0]){
         case SAMPLE_CMD1: // cmd without answer
             // handle cmd1
             break;
         case SAMPLE_CMD2: // cmd with answer 
             // handle cmd2, fill result
             result[1] = ...;
             result[2] = ...;
             *result_len = 3;
             break;
     }
     // return if max 1 pkt has to be sent. If >0 is returned, 
     // this procedure will be called again (to get the next pkt) 
     // until 0 is returned.
     return 0; 
 }

result procedure

 void _sample_cmd_result(u_char* source_addr, u_char* result, u_char result_len, 
                         void* arg)
 {
     u_char str[18];
     INFO(LOG_TERMINAL, "\n:XP %s\n", dbg_bt_addr_to_str(str, source_addr));
     switch(result[0]){
         case SAMPLE_CMD2:
                 INFO(LOG_TERMINAL, "PS u\n", 
                      result[1],
                      result[2]);
             break;
     }    
 }

register proc/result pair (usually in sample_init())

    rpc_register_proc(&_sample_stack->proc_nr,
                      _sample_cmd_proc, NULL,
                      _sample_cmd_result, NULL);  

terminal command parser

 void _sample_cmd_parser(u_char *arg){
     u_char query[SAMPLE_CMD_MAX_QUERY];
     u_char query_len = 0;
     if (!strncmp(arg, "cmd1", 4)) {
         query[0] = SAMPLE_CMD1;
         query_len = 1;
     }
     else if(!strncmp(arg, "cmd2", 4)){
         query[0] = SAMPLE_CMD2;
         query_len = 1;
     }
     if(query_len == 0){
         INFO(LOG_TERMINAL, "sample cmd parse error.\n");
     }
     else{
         rpc_handle_query(_sample_stack->proc_nr, query, query_len);
     }
 }