Contiki 3.x
Macros | Functions
res_sample.c File Reference

Sample resource. More...

#include "er-server.h"
#include "rest-engine.h"
#include "pb_decode.h"
#include "pb_encode.h"
#include "readings.pb.h"
#include "store.h"
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "debug.h"

Go to the source code of this file.

Macros

#define MAX_URI_LENGTH   20
 Maximum length of a URI.
 
#define NO_SAMPLE_ID   -1
 Indicates no trailing sample id was found in the URI.
 
#define INVALID_SAMPLE_ID   -2
 Indicates a sample id was found in the URI, but that it could not be sucesfully parsed.
 
#define SEPARATOR_CHAR   '/'
 The separator used in URIs, either as a character, or as a string literal.
 

Functions

static void res_get_handler (void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
 Get handler for Samples. More...
 
static void res_delete_handler (void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
 Delete handler for Samples. More...
 
static int16_t parse_sample_id (void *request)
 Parse a trailing sample id from a URI. More...
 
 PARENT_RESOURCE (res_sample,"Sample", res_get_handler, NULL, NULL, res_delete_handler)
 Sample ressource. More...
 

Detailed Description

Sample resource.

Serves stored samples, and can delete them. Arthur Fabre 2015

Definition in file res_sample.c.

Function Documentation

PARENT_RESOURCE ( res_sample  ,
"Sample"  ,
res_get_handler  ,
NULL  ,
NULL  ,
res_delete_handler   
)

Sample ressource.

Parent ressource as we use URL based parametes (like GET /sample/32)

int16_t parse_sample_id ( void *  request)
static

Parse a trailing sample id from a URI.

Deals with validating the ID, trailing slashes.

Returns
NO_SAMPLE_ID if no trailing sample id was found in the uri. INVALID_SAMPLE_ID If a trailing sample if was found, but it could not be parsed. The sample id on success.

Definition at line 157 of file res_sample.c.

References INVALID_SAMPLE_ID, MAX_URI_LENGTH, NO_SAMPLE_ID, NULL, and SEPARATOR_CHAR.

Referenced by res_delete_handler(), and res_get_handler().

void res_delete_handler ( void *  request,
void *  response,
uint8_t *  buffer,
uint16_t  preferred_size,
int32_t *  offset 
)
static

Delete handler for Samples.

Supports deleting arbitrary Samples. Format is DELETE /sample/23 to delete sample #23

Definition at line 135 of file res_sample.c.

References INVALID_SAMPLE_ID, NO_SAMPLE_ID, parse_sample_id(), and store_delete_sample().

void res_get_handler ( void *  request,
void *  response,
uint8_t *  buffer,
uint16_t  preferred_size,
int32_t *  offset 
)
static

Get handler for Samples.

Supports the optional param id. Serves latest if id isn't specified. Format is GET /sample/23 to get sample #23. GET /sample to get the latest sample.

Definition at line 72 of file res_sample.c.

References INVALID_SAMPLE_ID, NO_SAMPLE_ID, parse_sample_id(), store_get_latest_raw_sample(), and store_get_raw_sample().