2 * Copyright (c) 2011 Frank Lahm
3 * All Rights Reserved. See COPYRIGHT.
8 #endif /* HAVE_CONFIG_H */
10 #include <sys/queue.h>
17 #include <sys/types.h>
21 #include "event2/event-config.h"
23 #include "event2/event.h"
24 #include "event2/http.h"
25 #include "event2/event_compat.h"
26 #include "event2/http_compat.h"
27 #include "event2/rpc.h"
28 #include "event2/rpc_struct.h"
30 #include <atalk/logger.h>
31 #include <atalk/errchk.h>
32 #include <atalk/locking.h>
33 #include <atalk/adouble.h>
34 #include <atalk/bstrlib.h>
35 #include <atalk/bstradd.h>
36 #include <atalk/lockrpc.gen.h>
38 EVRPC_HEADER(lock_msg, lock_req, lock_rep)
39 EVRPC_GENERATE(lock_msg, lock_req, lock_rep)
41 static struct evrpc_pool *rpc_pool;
42 static struct event_base *ev_base;
44 static void ev_log_cb(int severity, const char *msg)
46 LOG(log_warning, logtype_default, (char *)msg);
49 static void msg_rep_cb(struct evrpc_status *status,
54 if (status->error != EVRPC_STATUS_ERR_NONE)
58 event_base_loopexit(ev_base, NULL);
61 static int rpc_dummy(const char *name)
63 struct lock *lock = NULL;
64 struct lock_req *lock_req = NULL;
65 struct lock_rep *lock_rep = NULL;
68 lock_req = lock_req_new();
69 lock_rep = lock_rep_new();
71 EVTAG_ASSIGN(lock_req, req_lock, lock);
72 EVTAG_ASSIGN(lock_req, req_filename, name);
74 EVRPC_MAKE_REQUEST(lock_msg, rpc_pool, lock_req, lock_rep, msg_rep_cb, NULL);
79 int rpc_lock(struct adouble *ad, uint32_t eid, int type, off_t off, off_t len, int user)
81 rpc_dummy(cfrombstr(ad->ad_fullpath));
85 void rpc_unlock(struct adouble *ad, int user)
87 rpc_dummy(cfrombstr(ad->ad_fullpath));
90 int rpc_tmplock(struct adouble *ad, uint32_t eid, int type, off_t off, off_t len, int user)
92 rpc_dummy(cfrombstr(ad->ad_fullpath));
96 /**************************************************************************************
98 **************************************************************************************/
100 int rpc_init(const char *addr, unsigned short port)
104 struct evhttp_connection *evcon;
106 EC_NULL_LOG(ev_base = event_init());
107 event_set_log_callback(ev_log_cb);
108 EC_NULL_LOG(rpc_pool = evrpc_pool_new(NULL));
109 EC_NULL_LOG(evcon = evhttp_connection_new(addr, port));
110 evrpc_pool_add_connection(rpc_pool, evcon);