| 6114 | } |
| 6115 | |
| 6116 | static void classify_layer(const char *pkg, int in, int out_deg, bool has_routes, |
| 6117 | bool has_entry_points, const char **layer, const char **reason) { |
| 6118 | static CBM_TLS char reason_buf[CBM_SZ_128]; |
| 6119 | if (has_entry_points && out_deg > 0 && in == 0) { |
| 6120 | *layer = "entry"; |
| 6121 | *reason = "has entry points, only outbound calls"; |
| 6122 | return; |
| 6123 | } |
| 6124 | if (has_routes) { |
| 6125 | *layer = "api"; |
| 6126 | *reason = "has HTTP route definitions"; |
| 6127 | return; |
| 6128 | } |
| 6129 | if (in > out_deg && in > ST_MIN_INDEGREE) { |
| 6130 | snprintf(reason_buf, sizeof(reason_buf), "high fan-in (%d in, %d out)", in, out_deg); |
| 6131 | *layer = "core"; |
| 6132 | *reason = reason_buf; |
| 6133 | return; |
| 6134 | } |
| 6135 | if (out_deg == 0 && in > 0) { |
| 6136 | *layer = "leaf"; |
| 6137 | *reason = "only inbound calls, no outbound"; |
| 6138 | return; |
| 6139 | } |
| 6140 | if (in == 0 && out_deg > 0) { |
| 6141 | *layer = "entry"; |
| 6142 | *reason = "only outbound calls"; |
| 6143 | return; |
| 6144 | } |
| 6145 | snprintf(reason_buf, sizeof(reason_buf), "fan-in=%d, fan-out=%d", in, out_deg); |
| 6146 | *layer = "internal"; |
| 6147 | *reason = reason_buf; |
| 6148 | (void)pkg; |
| 6149 | } |
| 6150 | |
| 6151 | /* Find or insert a package name, returning its index. Returns -1 if full. */ |
| 6152 | static int find_or_add_pkg(char **all_pkgs, int *npkgs, int max_pkgs, const char *pkg) { |