2424#include "utils/hsearch.h"
2525
2626static HTAB * extensible_node_methods = NULL ;
27+ static HTAB * custom_scan_methods = NULL ;
2728
2829typedef struct
2930{
3031 char extnodename [EXTNODENAME_MAX_LEN ];
31- const ExtensibleNodeMethods * methods ;
32+ const void * extnodemethods ;
3233} ExtensibleNodeEntry ;
3334
3435/*
35- * Register a new type of extensible node.
36+ * An internal function to register a new callback structure
3637 */
37- void
38- RegisterExtensibleNodeMethods (const ExtensibleNodeMethods * methods )
38+ static void
39+ RegisterExtensibleNodeEntry (HTAB * * p_htable , const char * htable_label ,
40+ const char * extnodename ,
41+ const void * extnodemethods )
3942{
4043 ExtensibleNodeEntry * entry ;
4144 bool found ;
4245
43- if (extensible_node_methods == NULL )
46+ if (* p_htable == NULL )
4447 {
4548 HASHCTL ctl ;
4649
4750 memset (& ctl , 0 , sizeof (HASHCTL ));
4851 ctl .keysize = EXTNODENAME_MAX_LEN ;
4952 ctl .entrysize = sizeof (ExtensibleNodeEntry );
50- extensible_node_methods = hash_create ( "Extensible Node Methods" ,
51- 100 , & ctl , HASH_ELEM );
53+
54+ * p_htable = hash_create ( htable_label , 100 , & ctl , HASH_ELEM );
5255 }
5356
54- if (strlen (methods -> extnodename ) >= EXTNODENAME_MAX_LEN )
57+ if (strlen (extnodename ) >= EXTNODENAME_MAX_LEN )
5558 elog (ERROR , "extensible node name is too long" );
5659
57- entry = (ExtensibleNodeEntry * ) hash_search (extensible_node_methods ,
58- methods -> extnodename ,
60+ entry = (ExtensibleNodeEntry * ) hash_search (* p_htable ,
61+ extnodename ,
5962 HASH_ENTER , & found );
6063 if (found )
6164 ereport (ERROR ,
6265 (errcode (ERRCODE_DUPLICATE_OBJECT ),
6366 errmsg ("extensible node type \"%s\" already exists" ,
64- methods -> extnodename )));
67+ extnodename )));
6568
66- entry -> methods = methods ;
69+ entry -> extnodemethods = extnodemethods ;
6770}
6871
6972/*
70- * Get the methods for a given type of extensible node.
73+ * Register a new type of extensible node.
7174 */
72- const ExtensibleNodeMethods *
73- GetExtensibleNodeMethods (const char * extnodename , bool missing_ok )
75+ void
76+ RegisterExtensibleNodeMethods (const ExtensibleNodeMethods * methods )
77+ {
78+ RegisterExtensibleNodeEntry (& extensible_node_methods ,
79+ "Extensible Node Methods" ,
80+ methods -> extnodename ,
81+ methods );
82+ }
83+
84+ /*
85+ * Register a new type of custom scan node
86+ */
87+ void
88+ RegisterCustomScanMethods (const CustomScanMethods * methods )
89+ {
90+ RegisterExtensibleNodeEntry (& custom_scan_methods ,
91+ "Custom Scan Methods" ,
92+ methods -> CustomName ,
93+ methods );
94+ }
95+
96+ /*
97+ * An internal routine to get an ExtensibleNodeEntry by the given identifier
98+ */
99+ static const void *
100+ GetExtensibleNodeEntry (HTAB * htable , const char * extnodename , bool missing_ok )
74101{
75102 ExtensibleNodeEntry * entry = NULL ;
76103
77- if (extensible_node_methods != NULL )
78- entry = (ExtensibleNodeEntry * ) hash_search (extensible_node_methods ,
104+ if (htable != NULL )
105+ entry = (ExtensibleNodeEntry * ) hash_search (htable ,
79106 extnodename ,
80107 HASH_FIND , NULL );
81-
82108 if (!entry )
83109 {
84110 if (missing_ok )
@@ -89,5 +115,29 @@ GetExtensibleNodeMethods(const char *extnodename, bool missing_ok)
89115 extnodename )));
90116 }
91117
92- return entry -> methods ;
118+ return entry -> extnodemethods ;
119+ }
120+
121+ /*
122+ * Get the methods for a given type of extensible node.
123+ */
124+ const ExtensibleNodeMethods *
125+ GetExtensibleNodeMethods (const char * extnodename , bool missing_ok )
126+ {
127+ return (const ExtensibleNodeMethods * )
128+ GetExtensibleNodeEntry (extensible_node_methods ,
129+ extnodename ,
130+ missing_ok );
131+ }
132+
133+ /*
134+ * Get the methods for a given name of CustomScanMethods
135+ */
136+ const CustomScanMethods *
137+ GetCustomScanMethods (const char * CustomName , bool missing_ok )
138+ {
139+ return (const CustomScanMethods * )
140+ GetExtensibleNodeEntry (custom_scan_methods ,
141+ CustomName ,
142+ missing_ok );
93143}
0 commit comments