Mercurial > vim
comparison src/channel.c @ 8669:06848fe9c816 v7.4.1624
commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 20 20:57:45 2016 +0100
patch 7.4.1624
Problem: Can't get info about a channel.
Solution: Add ch_info().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 20 Mar 2016 21:00:05 +0100 |
parents | 8c80c21a1885 |
children | a4e7f4a62193 |
comparison
equal
deleted
inserted
replaced
8668:9a56be645421 | 8669:06848fe9c816 |
---|---|
836 #endif | 836 #endif |
837 } | 837 } |
838 | 838 |
839 channel->CH_SOCK_FD = (sock_T)sd; | 839 channel->CH_SOCK_FD = (sock_T)sd; |
840 channel->ch_nb_close_cb = nb_close_cb; | 840 channel->ch_nb_close_cb = nb_close_cb; |
841 channel->ch_hostname = (char *)vim_strsave((char_u *)hostname); | |
842 channel->ch_port = port_in; | |
841 | 843 |
842 #ifdef FEAT_GUI | 844 #ifdef FEAT_GUI |
843 channel_gui_register_one(channel, PART_SOCK); | 845 channel_gui_register_one(channel, PART_SOCK); |
844 #endif | 846 #endif |
845 | 847 |
1136 channel->ch_part[PART_ERR].ch_buffer = | 1138 channel->ch_part[PART_ERR].ch_buffer = |
1137 find_buffer(opt->jo_io_name[PART_ERR], TRUE); | 1139 find_buffer(opt->jo_io_name[PART_ERR], TRUE); |
1138 ch_logs(channel, "writing err to buffer '%s'", | 1140 ch_logs(channel, "writing err to buffer '%s'", |
1139 (char *)channel->ch_part[PART_ERR].ch_buffer->b_ffname); | 1141 (char *)channel->ch_part[PART_ERR].ch_buffer->b_ffname); |
1140 } | 1142 } |
1143 | |
1144 channel->ch_part[PART_OUT].ch_io = opt->jo_io[PART_OUT]; | |
1145 channel->ch_part[PART_ERR].ch_io = opt->jo_io[PART_ERR]; | |
1146 channel->ch_part[PART_IN].ch_io = opt->jo_io[PART_IN]; | |
1141 } | 1147 } |
1142 | 1148 |
1143 /* | 1149 /* |
1144 * Set the callback for "channel"/"part" for the response with "id". | 1150 * Set the callback for "channel"/"part" for the response with "id". |
1145 */ | 1151 */ |
2086 if (channel_is_open(channel)) | 2092 if (channel_is_open(channel)) |
2087 return "open"; | 2093 return "open"; |
2088 return "closed"; | 2094 return "closed"; |
2089 } | 2095 } |
2090 | 2096 |
2097 static void | |
2098 channel_part_info(channel_T *channel, dict_T *dict, char *name, int part) | |
2099 { | |
2100 chanpart_T *chanpart = &channel->ch_part[part]; | |
2101 char namebuf[20]; | |
2102 int tail; | |
2103 char *s; | |
2104 | |
2105 STRCPY(namebuf, name); | |
2106 STRCAT(namebuf, "_"); | |
2107 tail = STRLEN(namebuf); | |
2108 | |
2109 STRCPY(namebuf + tail, "status"); | |
2110 dict_add_nr_str(dict, namebuf, 0, | |
2111 (char_u *)(chanpart->ch_fd == INVALID_FD ? "closed" : "open")); | |
2112 | |
2113 STRCPY(namebuf + tail, "mode"); | |
2114 switch (chanpart->ch_mode) | |
2115 { | |
2116 case MODE_NL: s = "NL"; break; | |
2117 case MODE_RAW: s = "RAW"; break; | |
2118 case MODE_JSON: s = "JSON"; break; | |
2119 case MODE_JS: s = "JS"; break; | |
2120 } | |
2121 dict_add_nr_str(dict, namebuf, 0, (char_u *)s); | |
2122 | |
2123 STRCPY(namebuf + tail, "io"); | |
2124 if (part == PART_SOCK) | |
2125 s = "socket"; | |
2126 else switch (chanpart->ch_io) | |
2127 { | |
2128 case JIO_NULL: s = "null"; break; | |
2129 case JIO_PIPE: s = "pipe"; break; | |
2130 case JIO_FILE: s = "file"; break; | |
2131 case JIO_BUFFER: s = "buffer"; break; | |
2132 case JIO_OUT: s = "out"; break; | |
2133 } | |
2134 dict_add_nr_str(dict, namebuf, 0, (char_u *)s); | |
2135 | |
2136 STRCPY(namebuf + tail, "timeout"); | |
2137 dict_add_nr_str(dict, namebuf, chanpart->ch_timeout, NULL); | |
2138 } | |
2139 | |
2140 void | |
2141 channel_info(channel_T *channel, dict_T *dict) | |
2142 { | |
2143 dict_add_nr_str(dict, "id", channel->ch_id, NULL); | |
2144 dict_add_nr_str(dict, "status", 0, (char_u *)channel_status(channel)); | |
2145 | |
2146 if (channel->ch_hostname != NULL) | |
2147 { | |
2148 dict_add_nr_str(dict, "hostname", 0, (char_u *)channel->ch_hostname); | |
2149 dict_add_nr_str(dict, "port", channel->ch_port, NULL); | |
2150 channel_part_info(channel, dict, "sock", PART_SOCK); | |
2151 } | |
2152 else | |
2153 { | |
2154 channel_part_info(channel, dict, "out", PART_OUT); | |
2155 channel_part_info(channel, dict, "err", PART_ERR); | |
2156 channel_part_info(channel, dict, "in", PART_IN); | |
2157 } | |
2158 } | |
2159 | |
2091 /* | 2160 /* |
2092 * Close channel "channel". | 2161 * Close channel "channel". |
2093 * Trigger the close callback if "invoke_close_cb" is TRUE. | 2162 * Trigger the close callback if "invoke_close_cb" is TRUE. |
2094 * Does not clear the buffers. | 2163 * Does not clear the buffers. |
2095 */ | 2164 */ |
2193 */ | 2262 */ |
2194 void | 2263 void |
2195 channel_clear(channel_T *channel) | 2264 channel_clear(channel_T *channel) |
2196 { | 2265 { |
2197 ch_log(channel, "Clearing channel"); | 2266 ch_log(channel, "Clearing channel"); |
2267 vim_free(channel->ch_hostname); | |
2268 channel->ch_hostname = NULL; | |
2198 channel_clear_one(channel, PART_SOCK); | 2269 channel_clear_one(channel, PART_SOCK); |
2199 channel_clear_one(channel, PART_OUT); | 2270 channel_clear_one(channel, PART_OUT); |
2200 channel_clear_one(channel, PART_ERR); | 2271 channel_clear_one(channel, PART_ERR); |
2201 vim_free(channel->ch_callback); | 2272 vim_free(channel->ch_callback); |
2202 channel->ch_callback = NULL; | 2273 channel->ch_callback = NULL; |