int usc_mrcp_service_set_option(HANDLE_MRCPINTF Handle,int option_id, const char* value) { char buf[48]; off_t offset = 0; PUSH_FUN(buf, offset, sizeof(buf)); PUSH_INT(buf, offset, sizeof(buf), option_id, sizeof(option_id)); PUSH_STR(buf, offset, sizeof(buf), value); PUSH_HEAD(buf, offset, sizeof(buf)); writen(Handle, buf, offset + 4); return 0; }
/* *|---------total len------------| *|--4 bytes---|offset len-------| */ int usc_mrcp_asr_init(HANDLE_MRCPINTF* asr, const char* configFile,unsigned int sessionNum) { char buf[512]; off_t offset = 0; //private_init(); int s = sock_connect(ip, port); if (s == -1) return -1; *asr = s; PUSH_FUN(buf, offset, sizeof(buf)); PUSH_STR(buf, offset, sizeof(buf), configFile); PUSH_INT(buf, offset, sizeof(buf), sessionNum, sizeof(unsigned int)); PUSH_HEAD(buf, offset, sizeof(buf)); writen(s, buf, offset + 4); /*read return value*/ return 0; }
int usc_mrcp_service_recognize(HANDLE_MRCPINTF Handle, char* buffer, int len, int lastSectFlag) { int size; off_t offset = 0; char *buf= NULL; size = 4 + sizeof(__func__) - 1 + 4 + len + 4 + sizeof(lastSectFlag); buf= malloc(size); if (!buf) { fprintf(stderr, "%s:%d malloc %m\n", __FILE__, __LINE__); return -1; } PUSH_FUN(buf, offset, size); PUSH_BUF(buf, offset, size, buffer, len); PUSH_INT(buf, offset, size, lastSectFlag, sizeof(lastSectFlag)); PUSH_HEAD(buf, offset, size); writen(Handle, buf, offset + 4); free(buf); return 0; }
int luaopen_cgroup(lua_State *L) { /* create metatable */ luaL_newmetatable(L, CGROUP_META); /* metatable.__index = metatable */ lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); /* register module */ luaL_register(L, "cgroups", R); /* register metatable as socket_meta */ lua_pushvalue(L, -2); lua_setfield(L, -2, "meta_cgroups"); /* module version */ // PUSH_INT(version, VERSION) PUSH_INT(CGFLAG_DELETE_IGNORE_MIGRATION, CGFLAG_DELETE_IGNORE_MIGRATION) PUSH_INT(CGFLAG_DELETE_RECURSIVE, CGFLAG_DELETE_RECURSIVE) // error ints PUSH_INT(ECGMOUNTNAMESPACE, ECGMOUNTNAMESPACE) PUSH_INT(ECGNAMESPACECONTROLLER, ECGNAMESPACECONTROLLER) PUSH_INT(ECGNAMESPACEPATHS, ECGNAMESPACEPATHS) PUSH_INT(ECGCONFIGPARSEFAIL, ECGCONFIGPARSEFAIL) PUSH_INT(ECGEOF, ECGEOF) PUSH_INT(ECGSENTINEL, ECGSENTINEL) PUSH_INT(ECGMOUNTFAIL, ECGMOUNTFAIL) PUSH_INT(ECGROUPNORULES, ECGROUPNORULES) PUSH_INT(ECGROUPPARSEFAIL, ECGROUPPARSEFAIL) PUSH_INT(ECGCONTROLLERNOTEQUAL, ECGCONTROLLERNOTEQUAL) PUSH_INT(ECGROUPNOTEQUAL, ECGROUPNOTEQUAL) PUSH_INT(ECGOTHER, ECGOTHER) PUSH_INT(ECGROUPVALUENOTEXIST, ECGROUPVALUENOTEXIST) PUSH_INT(ECGROUPNOTINITIALIZED, ECGROUPNOTINITIALIZED) PUSH_INT(ECGFAIL, ECGFAIL) PUSH_INT(ECGCONTROLLERCREATEFAILED, ECGCONTROLLERCREATEFAILED) PUSH_INT(ECGINVAL, ECGINVAL) PUSH_INT(ECGVALUEEXISTS, ECGVALUEEXISTS) PUSH_INT(ECGCONTROLLEREXISTS, ECGCONTROLLEREXISTS) PUSH_INT(ECGMAXVALUESEXCEEDED, ECGMAXVALUESEXCEEDED) PUSH_INT(ECGROUPNOTALLOWED, ECGROUPNOTALLOWED) PUSH_INT(ECGROUPMULTIMOUNTED, ECGROUPMULTIMOUNTED) PUSH_INT(ECGROUPNOTOWNER, ECGROUPNOTOWNER) PUSH_INT(ECGROUPSUBSYSNOTMOUNTED, ECGROUPSUBSYSNOTMOUNTED) PUSH_INT(ECGROUPNOTCREATED, ECGROUPNOTCREATED) PUSH_INT(ECGROUPNOTEXIST, ECGROUPNOTEXIST) PUSH_INT(ECGROUPNOTMOUNTED, ECGROUPNOTMOUNTED) PUSH_INT(ECGROUPNOTCOMPILED, ECGROUPNOTCOMPILED) /* remove meta table */ lua_remove(L, -2); // map cgroup luaL_register(L, CGROUP, cgroup_methods); luaL_newmetatable(L, CGROUP); luaL_register(L, NULL, cgroup_meta); lua_pushliteral(L, "__index"); lua_pushvalue(L, -3); lua_rawset(L, -3); /* metatable.__index = methods */ lua_pushliteral(L, "__metatable"); lua_pushvalue(L, -3); /* dup methods table*/ lua_rawset(L, -3); lua_pop(L, 1); // map cgroup_controller luaL_register(L, CGROUP_CONTROLLER, cgroup_controller_methods); luaL_newmetatable(L, CGROUP_CONTROLLER); luaL_register(L, NULL, cgroup_controller_meta); lua_pushliteral(L, "__index"); lua_pushvalue(L, -3); lua_rawset(L, -3); /* metatable.__index = methods */ lua_pushliteral(L, "__metatable"); lua_pushvalue(L, -3); /* dup methods table*/ lua_rawset(L, -3); lua_pop(L, 1); return 1; }