d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen#ifndef WORKER_CONNECTION_H
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen#define WORKER_CONNECTION_H
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen#include "indexer.h"
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen
294f579cd3803e2d9997231fdc46523c23774a8fTimo Sirainenstruct indexer_request;
294f579cd3803e2d9997231fdc46523c23774a8fTimo Sirainen
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenstruct worker_connection *
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenworker_connection_create(const char *socket_path,
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen indexer_status_callback_t *callback);
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenvoid worker_connection_destroy(struct worker_connection **conn);
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenint worker_connection_connect(struct worker_connection *conn);
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen/* Returns TRUE if worker is connected to (not necessarily handshaked yet) */
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenbool worker_connection_is_connected(struct worker_connection *conn);
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen/* After initial handshake the worker process tells how many of its kind
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen can be at maximum. This returns the value, of FALSE if handshake isn't
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen finished yet. */
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenbool worker_connection_get_process_limit(struct worker_connection *conn,
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen unsigned int *limit_r);
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen/* Send a new indexing request for username+mailbox. The status callback is
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen called as necessary with the given context. Requests can be queued, but
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen only for the same username. */
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenvoid worker_connection_request(struct worker_connection *conn,
294f579cd3803e2d9997231fdc46523c23774a8fTimo Sirainen const struct indexer_request *request,
294f579cd3803e2d9997231fdc46523c23774a8fTimo Sirainen void *context);
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen/* Returns TRUE if a request is being handled. */
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenbool worker_connection_is_busy(struct worker_connection *conn);
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen/* Returns username of the currently pending requests,
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen or NULL if there are none. */
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainenconst char *worker_connection_get_username(struct worker_connection *conn);
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen
d9e404180ff26dbbaea68534a5f176765022b76bTimo Sirainen#endif