Skip to content

Instantly share code, notes, and snippets.

@ficoos
Created June 6, 2013 05:33
Show Gist options
  • Save ficoos/5719524 to your computer and use it in GitHub Desktop.
Save ficoos/5719524 to your computer and use it in GitHub Desktop.
typedef int(*BuffOp)(char* buffer, void* ctx);
struct OpNode {
BuffOp op;
struct OpNode *next;
void* ctx;
};
int call_chain(struct OpNode* node, char* buffer) {
int rv;
if ((rv = node->op(buffer, node->ctx)) < 0) {
return rv;
}
if (node->next == 0) {
return 0;
}
return call_chain(node->next, buffer);
}
struct SelectCoreArgs {
int core_num;
};
int select_core(char* buffer, void* ctx) {
struct SelectCoreArgs *args = ctx;
// Selecting core
return 0;
}
int do_something(char* buffer, void* ctx) {
return 0;
}
int main() {
char *buffer = "Hello World";
struct OpNode op;
op.op = do_something;
op.ctx = op.next = 0;
struct OpNode select;
select.op = select_core;
struct SelectCoreArgs args;
args.core_num = 32;
select.ctx = &args;
select.next = &op;
call_chain(&select, buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment