GENERIC_SERVER  0.0.0.9
A light-weight, cross-platform, pluggable, extensible and secure framework for deploying C++ plug-ins.
 All Classes Files Functions Variables Typedefs Pages
Public Member Functions | Private Attributes | List of all members
sample_plugin Class Reference

Derived from GENERIC_PLUGIN. Implements virtual functions and all plug-in specific functionality. More...

#include <sample.h>

Inheritance diagram for sample_plugin:
generic_plugin

Public Member Functions

 sample_plugin (char *, int)
 
int shutdown_plugin (void)
 
int plugin_init (int)
 
int server_init (void)
 
int server_shutdown (void)
 
int process_request (void *, void *, unsigned int &)
 
int init (void)
 
int init (int)
 
string get_plugin_version (void)
 
int get_plugin_params (string line)
 
sample_pluginoperator= (const sample_plugin &)
 
string bootstrap_name (void)
 
bool bootstrap_init (string)
 
bool bootstrap_terminate (string)
 
- Public Member Functions inherited from generic_plugin
string generic_plugin_version ()
 
 generic_plugin (char *, int)
 
 generic_plugin (char *, char *, int)
 
GEN_PLUGIN_MUTEX create_mutex (void)
 
int lock_mutex (GEN_PLUGIN_MUTEX *)
 
int rel_mutex (GEN_PLUGIN_MUTEX *)
 
bool get_validate_plugin (void)
 
virtual unsigned short get_session (void)
 
SOCKET get_socket ()
 
int get_port ()
 
int get_thread_id ()
 
int get_tls_flag ()
 
string get_plugin ()
 
string get_plugin_name ()
 
string get_plugin_number ()
 
string get_plugin_path ()
 
int set_plugin (string)
 
int set_plugin_name (string)
 
int set_plugin_number (string)
 
int set_port (int)
 
int set_tls_flag (int)
 
int set_thread_id (int)
 
int set_socket (SOCKET)
 
int set_plugin_path (string)
 
int add_plugin_alias (string)
 
int clear_aliases ()
 
int aliases_count ()
 
string pop_alias ()
 
bool find_plugin_alias (string)
 
SOCKET initialize_socket (string port)
 Binds socket to TCP port, set options on new socket and do socket listen.
 
int set_client_socket (SOCKET)
 
int set_conf_file (string)
 
string get_conf_file ()
 
SOCKET get_client_socket (void)
 
generic_pluginoperator= (const generic_plugin &)
 
bool operator< (generic_plugin a)
 
bool operator== (generic_plugin a)
 

Private Attributes

string db_name
 
string db_passwd
 

Additional Inherited Members

- Public Attributes inherited from generic_plugin
unsigned long pinstance
 Pointer to 'framework' object.
 
string plugin_conf_file
 
- Protected Member Functions inherited from generic_plugin
int log (unsigned int, char *)
 
int log (unsigned int, string)
 
- Protected Attributes inherited from generic_plugin
SOCKET server_socket
 
SOCKET client_socket
 
int port
 
int tls_enabled
 
int thread_id
 
char * local_ip_address
 
string plugin_type
 
string plugin_name
 
string plugin_number
 
string plugin_lib_path
 
unsigned int networking
 
unsigned int verbose_level
 
bool validate_plugin
 
vector< string > v_plugin_aliases
 

Detailed Description

Derived from GENERIC_PLUGIN. Implements virtual functions and all plug-in specific functionality.

Definition at line 38 of file sample.h.

Member Function Documentation

bool sample_plugin::bootstrap_init ( string  str)
virtual

This method gets invoked by the framework when it is being booted up. This method is invoked only once per 'bootstrap_name', each time framework is started up. If there are three plug-ins in generic_server conf file, all of them belonging to different plug-in types and each of them defines the same 'bootstrap_name', then this method gets called only once when the first plug-in is loaded Please note, this method gets invoked during framework start-up time - not during client session initiation. This would be the place to do stuff like:

  • Any one-time initialization (not per session) required by plug-ins belonging to different plug-in types
  • Dynamically load any shared library required by any plug-in

Reimplemented from generic_plugin.

Definition at line 218 of file sample.cpp.

219 {
220  // Do all bootstrapping stuff here. Load dlls,shared libs, initialize 3rd party apps etc
221  // Don't bother about thread sync here, Framework will take care of it!
222  return(true);
223 }
string sample_plugin::bootstrap_name ( void  )
virtual

GENERIC_SERVER framework provides a feature where plug-ins could request framework to call one or more bootstrap methods when framework is being bootsrapped. Any plug-in could implement 'bootstrap' methods. 'bootstrap_name' is the name associated with a specific 'bootstrap' method. Plug-ins should be co-operative and set differnet bootstrap_names to identify and implement different tasks. Under no circumstances should different plug-ins define the same 'bootstrap_name', if such a case should ever occur, framework will ignore the latter defined and implemented bootstrap method.

Reimplemented from generic_plugin.

Definition at line 212 of file sample.cpp.

213 {
214  return(string("INIT_SMART_CARD"));
215 }
bool sample_plugin::bootstrap_terminate ( string  )
virtual

This is the opposite of 'bootstrap_init()', framework invokes this method once for a 'bootstrap_name' when framework is being terminated.

Reimplemented from generic_plugin.

Definition at line 226 of file sample.cpp.

227 {
228  // Do all bootstrapping cleanup stuff here. Unload dlls,shared libs,3rd party apps etc
229  // Don't bother about thread sync here, Framework will take care of it!
230  return(true);
231 }
int sample_plugin::get_plugin_params ( string  line)
virtual

Read plug-in configuration data

Framework presents configuration information from plug-in conf file to be processed.
This method will be invoked once per line in plug-in conf file.
Parameters
[in]lineOne line from plug-in conf file.
Returns
1 on success, 0 on failure.

Reimplemented from generic_plugin.

Definition at line 195 of file sample.cpp.

References generic_plugin::get_plugin_params().

196 {
198  if (line.size() > 8 && line.compare(0,8,"DB_NAME=") == 0)
199  {
200  db_name = line.substr(8);
201  return(0);
202  }
203  if (line.size() > 10 && line.compare(0,10,"DB_PASSWD=") == 0)
204  {
205  db_passwd = line.substr(10);
206  return(0);
207  }
208  return(1);
209 }
virtual int get_plugin_params(string line)
int sample_plugin::plugin_init ( int  thread_no)
virtual

Initialize plug-in

This method gets invoked whenever a new client session gets initiated.
Parameters
[in]thread_noThe thread number assigned to plug-in.
Returns
1 on success, 0 on failure.

Reimplemented from generic_plugin.

Definition at line 79 of file sample.cpp.

80 {
81  ostringstream oss;
82 
83  try
84  {
85  oss << " Thr.ID:" << thread_no << " Plugin:" << plugin_name << " Successfully initialized session.";
86  log(LOG_HI,oss.str());
87  return(1);
88  }
89  catch(const exception& er)
90  {
91  oss << " Thr.ID:" << thread_no << " Plugin:" << plugin_name << " " << er.what();
92  log(LOG_HI,oss.str());
93  return(0);
94  }
95 }
int sample_plugin::process_request ( void *  buffer,
void *  out_buff,
unsigned int &  size 
)
virtual

Handle client request

Framework presents client input data to plug-in to process.
Parameters
[in]bufferRequest sent by client.
[out]outbuffResponse to be sent back to client.
[in,out]send_bytesSize of input buffer sent by client, function sets this to size of outbuff.
Returns
TERMINATE_SESSION to indicate plug-in done with the session with client or CONTINUE_SESSION to indicate plug-in want to continue session with client and process more requests.

Reimplemented from generic_plugin.

Definition at line 169 of file sample.cpp.

References generic_plugin::pinstance.

170 {
172  ostringstream oss;
173 
174  memset(out_buff,0,MAX_SZ);
175  oss << " Thr.ID:" << thread_id << " Plugin:" << plugin_name << " Received: " << string((char *)buffer,size);
176  log(LOG_LOW,oss.str());
177  if(!memcmp(buffer,"QUIT",4))
178  {
179  size = 12;
180  memcpy((char *)out_buff,"00 TERMINATE",size);
181  return(TERMINATE_SESSION);
182  }
183  size = 22;
184  memcpy((char *)out_buff,"response from plugin..",size);
185  return(CONTINUE_SESSION);
186 }
This is a singleton class and provides framework functionality.
unsigned long pinstance
Pointer to 'framework' object.
int sample_plugin::server_init ( void  )
virtual

This method gets invoked by the framework once per plug-in type when it is getting started. Please note, this method is invoked only ONCE for a particular plug-in type. If there are three plug-ins in generic_server conf file, all of them belonging to same plug-in_type, then this method gets called only once when the first plug-in is loaded. Please note, this method gets invoked during framework start-up in the MAIN thread. This would be the place to do stuff like:

  • Any one-time initialization (not per session) required by one or plug-in(s) belonging to same plug-in type
  • Store any information required to be shared across multiple instances of a plug-in into plug-in object as 'static' variable(s)

Reimplemented from generic_plugin.

Definition at line 131 of file sample.cpp.

132 {
133  ostringstream oss;
134 
135  try
136  {
137  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " Successfully initialized sample server.";
138  log(LOG_HI,oss.str());
139  return(1);
140  }
141  catch(const exception& er)
142  {
143  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " " << er.what();
144  log(LOG_HI,oss.str());
145  return(0);
146  }
147 }
int sample_plugin::server_shutdown ( void  )
virtual

This is the opposite of 'server_init()', framework invokes this method when a plug-in is removed from generic_server conf file. Similar to 'server_init()', 'server_shutdown()' gets invoked only once when the last plug-in of a plug-in_type is removed.

Reimplemented from generic_plugin.

Definition at line 150 of file sample.cpp.

151 {
152  ostringstream oss;
153 
154  try
155  {
156  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " Successfully shutdown sample server.";
157  log(LOG_HI,oss.str());
158  return(1);
159  }
160  catch(const exception& er)
161  {
162  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " " << er.what();
163  log(LOG_HI,oss.str());
164  return(0);
165  }
166 }
int sample_plugin::shutdown_plugin ( void  )
virtual

Terminate plug-in session

This method gets invoked whenever a client session gets terminated.
Returns
1 on success, 0 on failure. This is the opposite of 'plugin_init()', framework invokes this method when a client session is getting terminated.

Reimplemented from generic_plugin.

Definition at line 110 of file sample.cpp.

References generic_plugin::pinstance.

111 {
112  ostringstream oss;
114 
115  try
116  {
117 // Do plug-in cleanup here..
118  oss << " Thr.ID:" << thread_id << " Plugin:" << plugin_name << " Successfully shutdown session.";
119  log(LOG_HI,oss.str());
120  }
121  catch(const exception& er)
122  {
123  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " " << er.what();
124  log(LOG_HI,oss.str());
125  return 0;
126  }
127  return(1);
128 }
This is a singleton class and provides framework functionality.
unsigned long pinstance
Pointer to 'framework' object.

The documentation for this class was generated from the following files: