static void set_arg(PyObject * pValue, int pos) { if (!pValue) { fun_error("Cannot convert argument", ""); } PyTuple_SetItem(pArgs, pos, pValue); }
int main (int argc, char **argv) { /* initialize gthread */ g_thread_init (NULL); /* set the locale */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* initialize gtk library */ gtk_init (&argc, &argv); /* initialize dbus and exit if init fails */ if (fun_dbus_init() == FALSE) { fun_error (_("Error"), _("Failed to initialize dbus subsystem")); return -1; } /* initialize fun configuration */ fun_config_init (); /* initialize fun user interface */ if (!fun_glade_init()) { fun_error (_("Error"), _("Failed to initialize interface")); return -1; } fun_news_backend_init (); fun_ui_init (); /* run the gtk+ main loop */ gdk_threads_enter (); gtk_main (); gdk_threads_leave (); fun_ui_cleanup (); return 0; }
void agent_act(unsigned char * img_bytes, int img_width, int img_height, bool_t img_is_belly, int pass_button, navdata_unpacked_t * navdata, commands_t * commands) { int k = 0; PyObject *pImageBytes = PyByteArray_FromStringAndSize((const char *)img_bytes, img_width*img_height*3); set_arg(pImageBytes, k++); set_int_arg(img_width, k++); set_int_arg(img_height, k++); set_int_arg(img_is_belly?1:0, k++); set_int_arg(pass_button, k++); navdata_demo_t demo = navdata->navdata_demo; set_int_arg(demo.ctrl_state, k++); set_int_arg(demo.vbat_flying_percentage, k++); set_float_arg(demo.theta, k++); set_float_arg(demo.phi, k++); set_float_arg(demo.psi, k++); set_int_arg(navdata->navdata_altitude.altitude_raw, k++); navdata_vision_raw_t vision_raw = navdata->navdata_vision_raw; set_float_arg(vision_raw.vision_tx_raw, k++); set_float_arg(vision_raw.vision_ty_raw, k++); PyObject * pResult = PyObject_CallObject(pFunc, pArgs); if (!pResult) { fun_error("Call failed\n", ""); } k = 0; commands->zap = get_int_result(pResult, k++); commands->phi = get_float_result(pResult, k++); commands->theta = get_float_result(pResult, k++); commands->gaz = get_float_result(pResult, k++); commands->yaw = get_float_result(pResult, k++); }
// 处理新链接 void TcpListener::accept() { m_accept.async_accept(m_socket, [&, this](const boost::system::error_code& er){ if (er) { fun_error(er.message()); } if (!m_accept.is_open()) { return; } if (!er) { event_new_session(m_socket); } accept(); }); }