Added the first Antelope example: a simple command-line interface to the DBMS.
This commit is contained in:
parent
bbddbdee05
commit
639bb72855
8
examples/antelope/shell/Makefile
Normal file
8
examples/antelope/shell/Makefile
Normal file
|
@ -0,0 +1,8 @@
|
|||
CONTIKI = ../../../
|
||||
|
||||
APPS += antelope unit-test
|
||||
|
||||
CFLAGS += -Wall -g -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
SMALL = 1
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
5
examples/antelope/shell/project-conf.h
Normal file
5
examples/antelope/shell/project-conf.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#undef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 4
|
||||
|
||||
#undef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
109
examples/antelope/shell/shell-db.c
Normal file
109
examples/antelope/shell/shell-db.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A small command-line interface for the database system.
|
||||
* \author
|
||||
* Nicolas Tsiftes <nvt@sics.se>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/serial-line.h"
|
||||
|
||||
#include "antelope.h"
|
||||
|
||||
PROCESS(db_shell, "DB shell");
|
||||
AUTOSTART_PROCESSES(&db_shell);
|
||||
|
||||
PROCESS_THREAD(db_shell, ev, data)
|
||||
{
|
||||
static db_handle_t handle;
|
||||
db_result_t result;
|
||||
static tuple_id_t matching;
|
||||
static tuple_id_t processed;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
db_init();
|
||||
|
||||
for(;;) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL);
|
||||
|
||||
result = db_query(&handle, data);
|
||||
if(DB_ERROR(result)) {
|
||||
printf("Query \"%s\" failed: %s\n",
|
||||
(char *)data, db_get_result_message(result));
|
||||
db_free(&handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!db_processing(&handle)) {
|
||||
printf("OK\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
db_print_header(&handle);
|
||||
|
||||
matching = 0;
|
||||
processed = 0;
|
||||
|
||||
while(db_processing(&handle)) {
|
||||
PROCESS_PAUSE();
|
||||
result = db_process(&handle);
|
||||
switch(result) {
|
||||
case DB_GOT_ROW:
|
||||
/* The processed tuple matched the condition in the query. */
|
||||
matching++;
|
||||
processed++;
|
||||
db_print_tuple(&handle);
|
||||
break;
|
||||
case DB_OK:
|
||||
/* A tuple was processed, but did not match the condition. */
|
||||
processed++;
|
||||
continue;
|
||||
case DB_FINISHED:
|
||||
/* The processing has finished. Wait for a new command. */
|
||||
printf("[%ld tuples returned; %ld tuples processed]\n",
|
||||
(long)matching, (long)processed);
|
||||
printf("OK\n");
|
||||
default:
|
||||
if(DB_ERROR(result)) {
|
||||
printf("Processing error: %s\n", db_get_result_message(result));
|
||||
}
|
||||
db_free(&handle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
Loading…
Reference in a new issue