-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
=
committed
Jun 16, 2015
1 parent
0e89738
commit 135f45d
Showing
8 changed files
with
181 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* CamIO - The Cambridge Input/Output API | ||
* Copyright (c) 2015, All rights reserved. | ||
* See LICENSE.txt for full details. | ||
* | ||
* Created: Jun 16, 2015 | ||
* File name: spin_mux.c | ||
* Description: | ||
* A very simple spinning multiplexer. This will work ok so long as you don't mind burning a CPU and the rate at which new | ||
* transports come and go is low. | ||
*/ | ||
|
||
#include "mux.h" | ||
#include <src/types/muxable_vec.h> | ||
|
||
typedef struct { | ||
CH_VECTOR(CAMIO_MUXABLE_VEC)* muxables; | ||
ch_word idx; | ||
} mux_spin_priv_t; | ||
|
||
camio_error_t spin_construct(camio_mux_t* this){ | ||
mux_spin_priv_t* priv = MUX_GET_PRIVATE(this); | ||
priv->muxables = CH_VECTOR_NEW(CAMIO_MUXABLE_VEC,1024,CH_VECTOR_CMP(CAMIO_MUXABLE_VEC)); | ||
if(!priv->muxables){ | ||
return CAMIO_ENOMEM; | ||
} | ||
|
||
priv->idx = 0; | ||
return CAMIO_ENOERROR; | ||
} | ||
|
||
|
||
camio_error_t spin_insert(camio_mux_t* this, camio_muxable_t* muxable) | ||
{ | ||
mux_spin_priv_t* priv = MUX_GET_PRIVATE(this); | ||
CH_VECTOR(CAMIO_MUXABLE_VEC)* muxables = priv->muxables; | ||
muxables->push_back(muxables, *muxable); | ||
return CAMIO_ENOERROR; | ||
} | ||
|
||
|
||
camio_error_t spin_remove(camio_mux_t* this, camio_muxable_t* muxable) | ||
{ | ||
mux_spin_priv_t* priv = MUX_GET_PRIVATE(this); | ||
CH_VECTOR(CAMIO_MUXABLE_VEC)* muxables = priv->muxables; | ||
camio_muxable_t* result = muxables->find(muxables, muxables->first, muxables->end, *muxable); | ||
if(!result){ | ||
return CAMIO_EINVALID; //TODO XXX figure out better names for this | ||
} | ||
muxables->remove(muxables, result); //This may be a little expensive depending on the rate. | ||
|
||
return CAMIO_NOTIMPLEMENTED; | ||
} | ||
|
||
|
||
camio_error_t spin_select(camio_mux_t* this, struct timespec timeout, camio_muxable_t** muxable_o) | ||
{ | ||
(void)timeout; //Ignore the timeouts for the moment | ||
|
||
mux_spin_priv_t* priv = MUX_GET_PRIVATE(this); | ||
CH_VECTOR(CAMIO_MUXABLE_VEC)* muxables = priv->muxables; | ||
|
||
while(1){ | ||
priv->idx %= muxables->count; //Adjust for overflow | ||
camio_muxable_t* muxable = muxables->off(muxables,priv->idx); | ||
if(muxable->vtable.ready(muxable)){ | ||
priv->idx += 1;//Make sure we look at the next transport first | ||
*muxable_o = muxable; | ||
return CAMIO_ENOERROR; | ||
} | ||
|
||
priv->idx += 1; | ||
} | ||
return CAMIO_NOTIMPLEMENTED; | ||
} | ||
|
||
void spin_destroy(camio_mux_t* this) | ||
{ | ||
mux_spin_priv_t* priv = MUX_GET_PRIVATE(this); | ||
if(priv->muxables){ | ||
CH_VECTOR(CAMIO_MUXABLE_VEC)* muxables = priv->muxables; | ||
muxables->delete(muxables); | ||
} | ||
free(this); | ||
return; | ||
} | ||
|
||
|
||
NEW_MUX_DEFINE(spin,mux_spin_priv_t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* CamIO - The Cambridge Input/Output API | ||
* Copyright (c) 2015, All rights reserved. | ||
* See LICENSE.txt for full details. | ||
* | ||
* Created: Jun 16, 2015 | ||
* File name: spin_mux.h | ||
* Description: | ||
* <INSERT DESCRIPTION HERE> | ||
*/ | ||
#include "mux.h" | ||
|
||
NEW_MUX_DECLARE(spin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* CamIO - The Cambridge Input/Output API | ||
* Copyright (c) 2015, All rights reserved. | ||
* See LICENSE.txt for full details. | ||
* | ||
* Created: Jun 16, 2015 | ||
* File name: muxable_vec.c | ||
* Description: | ||
* <INSERT DESCRIPTION HERE> | ||
*/ | ||
|
||
#include "types.h" | ||
#include <deps/chaste/data_structs/vector/vector_typed_define_template.h> | ||
#include "muxable_vec.h" | ||
|
||
#include <src/multiplexers/muxable.h> | ||
|
||
define_ch_vector(CAMIO_MUXABLE_VEC,camio_muxable_t) | ||
define_ch_vector_compare(CAMIO_MUXABLE_VEC,camio_muxable_t) | ||
{ | ||
return memcmp(lhs,rhs,sizeof(camio_muxable_t)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* CamIO - The Cambridge Input/Output API | ||
* Copyright (c) 2015, All rights reserved. | ||
* See LICENSE.txt for full details. | ||
* | ||
* Created: Jun 16, 2015 | ||
* File name: muxable_vec.h | ||
* Description: | ||
* <INSERT DESCRIPTION HERE> | ||
*/ | ||
#ifndef MUXABLE_VEC_H_ | ||
#define MUXABLE_VEC_H_ | ||
|
||
#include <src/types/transport_params_vec.h> | ||
#include <deps/chaste/data_structs/vector/vector_typed_declare_template.h> | ||
|
||
declare_ch_vector(CAMIO_MUXABLE_VEC,camio_muxable_t) | ||
declare_ch_vector_cmp(CAMIO_MUXABLE_VEC,camio_muxable_t) | ||
|
||
#endif /* MUXABLE_VEC_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters