Created
June 6, 2013 05:33
-
-
Save ficoos/5719524 to your computer and use it in GitHub Desktop.
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
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