ANSI C
Don't use //
comments but /**/
. Don't use //
comments but /**/
.
Design away invalid states
It probably will never happen and is only in your mockup code but your design allows for the state
zoomingIn = true;
zoomingOut = true;
These two are mutually exclusive so you might consider to use a tristate (enum) like:
typedef enum {
ZOOMING_IN,
ZOOMING_STOPPED,
ZOOMING_OUT,
} zooming_state;
And having the state managed in one variable zooming
(or something with a better name then).
Switch to the rescue
Why don't you use a switch
for the commandmapping?
switch(applicationRequest->queryId) {
case WRITE_DEMO:
if (!unabto_query_write_uint8(writeBuffer, getDemoValue())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case READ_DEMO: {
uint8_t x;
if (!unabto_query_read_uint8(readBuffer, &x)){
return AER_REQ_TOO_SMALL;
}
setDemoValue(x);
return AER_REQ_RESPONSE_READY;
}
case ZOOM_CAPABLE:
if (!unabto_query_write_uint8(readBuffer, canZoom())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case ZOOM_IN:
startZoomIn();
return AER_REQ_RESPONSE_READY;
case ZOOM_OUT:
startZoomOut();
return AER_REQ_RESPONSE_READY;
case ZOOM_STOP:
stopZoom();
return AER_REQ_RESPONSE_READY;
default:
return AER_REQ_NO_QUERY_ID;
}
That looks much cleaner to me and it can handle the sparse indices as well (and with automatic compileroptimization!).
ANSI C
Don't use //
comments but /**/
.
Design away invalid states
It probably will never happen and is only in your mockup code but your design allows for the state
zoomingIn = true;
zoomingOut = true;
These two are mutually exclusive so you might consider to use a tristate (enum) like:
typedef enum {
ZOOMING_IN,
ZOOMING_STOPPED,
ZOOMING_OUT,
} zooming_state;
And having the state managed in one variable zooming
(or something with a better name then).
Switch to the rescue
Why don't you use a switch
for the commandmapping?
switch(applicationRequest->queryId) {
case WRITE_DEMO:
if (!unabto_query_write_uint8(writeBuffer, getDemoValue())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case READ_DEMO: {
uint8_t x;
if (!unabto_query_read_uint8(readBuffer, &x)){
return AER_REQ_TOO_SMALL;
}
setDemoValue(x);
return AER_REQ_RESPONSE_READY;
}
case ZOOM_CAPABLE:
if (!unabto_query_write_uint8(readBuffer, canZoom())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case ZOOM_IN:
startZoomIn();
return AER_REQ_RESPONSE_READY;
case ZOOM_OUT:
startZoomOut();
return AER_REQ_RESPONSE_READY;
case ZOOM_STOP:
stopZoom();
return AER_REQ_RESPONSE_READY;
default:
return AER_REQ_NO_QUERY_ID;
}
That looks much cleaner to me and it can handle the sparse indices as well (and with automatic compileroptimization!).
ANSI C
Don't use //
comments but /**/
.
Design away invalid states
It probably will never happen and is only in your mockup code but your design allows for the state
zoomingIn = true;
zoomingOut = true;
These two are mutually exclusive so you might consider to use a tristate (enum) like:
typedef enum {
ZOOMING_IN,
ZOOMING_STOPPED,
ZOOMING_OUT,
} zooming_state;
And having the state managed in one variable zooming
(or something with a better name then).
Switch to the rescue
Why don't you use a switch
for the commandmapping?
switch(applicationRequest->queryId) {
case WRITE_DEMO:
if (!unabto_query_write_uint8(writeBuffer, getDemoValue())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case READ_DEMO: {
uint8_t x;
if (!unabto_query_read_uint8(readBuffer, &x)){
return AER_REQ_TOO_SMALL;
}
setDemoValue(x);
return AER_REQ_RESPONSE_READY;
}
case ZOOM_CAPABLE:
if (!unabto_query_write_uint8(readBuffer, canZoom())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case ZOOM_IN:
startZoomIn();
return AER_REQ_RESPONSE_READY;
case ZOOM_OUT:
startZoomOut();
return AER_REQ_RESPONSE_READY;
case ZOOM_STOP:
stopZoom();
return AER_REQ_RESPONSE_READY;
default:
return AER_REQ_NO_QUERY_ID;
}
That looks much cleaner to me and it can handle the sparse indices as well (and with automatic compileroptimization!).
ANSI C
Don't use //
comments but /**/
.
Design away invalid states
It probably will never happen and is only in your mockup code but your design allows for the state
zoomingIn = true;
zoomingOut = true;
These two are mutually exclusive so you might consider to use a tristate (enum) like:
typedef enum {
ZOOMING_IN,
ZOOMING_STOPPED,
ZOOMING_OUT,
} zooming_state;
And having the state managed in one variable zooming
(or something with a better name then).
Switch to the rescue
Why don't you use a switch
for the commandmapping?
switch(applicationRequest->queryId) {
case WRITE_DEMO:
if (!unabto_query_write_uint8(writeBuffer, getDemoValue())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case READ_DEMO: {
uint8_t x;
if (!unabto_query_read_uint8(readBuffer, &x)){
return AER_REQ_TOO_SMALL;
}
setDemoValue(x);
return AER_REQ_RESPONSE_READY;
}
case ZOOM_CAPABLE:
if (!unabto_query_write_uint8(readBuffer, canZoom())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case ZOOM_IN:
startZoomIn();
return AER_REQ_RESPONSE_READY;
case ZOOM_OUT:
startZoomOut();
return AER_REQ_RESPONSE_READY;
case ZOOM_STOP:
stopZoom();
return AER_REQ_RESPONSE_READY;
default:
return AER_REQ_NO_QUERY_ID;
}
That looks much cleaner to me and it can handle the sparse indices as well (and with automatic compileroptimization!).
ANSI C
Don't use //
comments but /**/
.
Design away invalid states
It probably will never happen and is only in your mockup code but your design allows for the state
zoomingIn = true;
zoomingOut = true;
These two are mutually exclusive so you might consider to use a tristate (enum) like:
typedef enum {
ZOOMING_IN,
ZOOMING_STOPPED,
ZOOMING_OUT,
} zooming_state;
And having the state managed in one variable zooming
(or something with a better name then).
Switch to the rescue
Why don't you use a switch
for the commandmapping?
switch(applicationRequest->queryId) {
case WRITE_DEMO:
if (!unabto_query_write_uint8(writeBuffer, getDemoValue())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case READ_DEMO: {
uint8_t x;
if (!unabto_query_read_uint8(readBuffer, &x)){
return AER_REQ_TOO_SMALL;
}
setDemoValue(x);
return AER_REQ_RESPONSE_READY;
}
case ZOOM_CAPABLE:
if (!unabto_query_write_uint8(readBuffer, canZoom())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case ZOOM_IN:
startZoomIn();
return AER_REQ_RESPONSE_READY;
case ZOOM_OUT:
startZoomOut();
return AER_REQ_RESPONSE_READY;
case ZOOM_STOP:
stopZoom();
return AER_REQ_RESPONSE_READY;
default:
return AER_REQ_NO_QUERY_ID;
}
That looks much cleaner to me and it can handle the sparse indices as well (and with automatic compileroptimization!).
ANSI C
Don't use //
comments but /**/
.
Design away invalid states
It probably will never happen and is only in your mockup code but your design allows for the state
zoomingIn = true;
zoomingOut = true;
These two are mutually exclusive so you might consider to use a tristate (enum) like:
typedef enum {
ZOOMING_IN,
ZOOMING_STOPPED,
ZOOMING_OUT,
} zooming_state;
And having the state managed in one variable zooming
(or something with a better name then).
Switch to the rescue
Why don't you use a switch
for the commandmapping?
switch(applicationRequest->queryId) {
case WRITE_DEMO:
if (!unabto_query_write_uint8(writeBuffer, getDemoValue())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case READ_DEMO: {
uint8_t x;
if (!unabto_query_read_uint8(readBuffer, &x)){
return AER_REQ_TOO_SMALL;
}
setDemoValue(x);
return AER_REQ_RESPONSE_READY;
}
case ZOOM_CAPABLE:
if (!unabto_query_write_uint8(readBuffer, canZoom())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case ZOOM_IN:
startZoomIn();
return AER_REQ_RESPONSE_READY;
case ZOOM_OUT:
startZoomOut();
return AER_REQ_RESPONSE_READY;
case ZOOM_STOP:
stopZoom();
return AER_REQ_RESPONSE_READY;
default:
return AER_REQ_NO_QUERY_ID;
}
That looks much cleaner to me and it can handle the sparse indices as well (and with automatic compileroptimization!).
ANSI C
Don't use //
comments but /**/
.
Design away invalid states
It probably will never happen and is only in your mockup code but your design allows for the state
zoomingIn = true;
zoomingOut = true;
These two are mutually exclusive so you might consider to use a tristate (enum) like:
typedef enum {
ZOOMING_IN,
ZOOMING_STOPPED,
ZOOMING_OUT,
} zooming_state;
And having the state managed in one variable zooming
(or something with a better name then).
Switch to the rescue
Why don't you use a switch
for the commandmapping?
switch(applicationRequest->queryId) {
case WRITE_DEMO:
if (!unabto_query_write_uint8(writeBuffer, getDemoValue())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case READ_DEMO: {
uint8_t x;
if (!unabto_query_read_uint8(readBuffer, &x)){
return AER_REQ_TOO_SMALL;
}
setDemoValue(x);
return AER_REQ_RESPONSE_READY;
}
case ZOOM_CAPABLE:
if (!unabto_query_write_uint8(readBuffer, canZoom())){
return AER_REQ_RSP_TOO_LARGE;
}
return AER_REQ_RESPONSE_READY;
case ZOOM_IN:
startZoomIn();
return AER_REQ_RESPONSE_READY;
case ZOOM_OUT:
startZoomOut();
return AER_REQ_RESPONSE_READY;
case ZOOM_STOP:
stopZoom();
return AER_REQ_RESPONSE_READY;
default:
return AER_REQ_NO_QUERY_ID;
}
That looks much cleaner to me and it can handle the sparse indices as well (and with automatic compileroptimization!).