| OLD | NEW |
| (Empty) |
| 1 /* Licensed to the Apache Software Foundation (ASF) under one or more | |
| 2 * contributor license agreements. See the NOTICE file distributed with | |
| 3 * this work for additional information regarding copyright ownership. | |
| 4 * The ASF licenses this file to You under the Apache License, Version 2.0 | |
| 5 * (the "License"); you may not use this file except in compliance with | |
| 6 * the License. You may obtain a copy of the License at | |
| 7 * | |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 * | |
| 10 * Unless required by applicable law or agreed to in writing, software | |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 * See the License for the specific language governing permissions and | |
| 14 * limitations under the License. | |
| 15 */ | |
| 16 | |
| 17 /* | |
| 18 * | |
| 19 * @author Mladen Turk | |
| 20 * @version $Id: shm.c 1442587 2013-02-05 13:49:48Z rjung $ | |
| 21 */ | |
| 22 | |
| 23 #include "tcn.h" | |
| 24 #include "apr_shm.h" | |
| 25 | |
| 26 TCN_IMPLEMENT_CALL(jlong, Shm, create)(TCN_STDARGS, jlong reqsize, | |
| 27 jstring filename, | |
| 28 jlong pool) | |
| 29 { | |
| 30 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 31 const char *fname = NULL; | |
| 32 apr_shm_t *shm; | |
| 33 | |
| 34 | |
| 35 UNREFERENCED(o); | |
| 36 if (filename) | |
| 37 fname = (const char *)((*e)->GetStringUTFChars(e, filename, 0)); | |
| 38 TCN_THROW_IF_ERR(apr_shm_create(&shm, (apr_size_t)reqsize, | |
| 39 fname, p), shm); | |
| 40 | |
| 41 cleanup: | |
| 42 if (fname) | |
| 43 (*e)->ReleaseStringUTFChars(e, filename, fname); | |
| 44 return P2J(shm); | |
| 45 } | |
| 46 | |
| 47 TCN_IMPLEMENT_CALL(jint, Shm, remove)(TCN_STDARGS, | |
| 48 jstring filename, | |
| 49 jlong pool) | |
| 50 { | |
| 51 apr_status_t rv; | |
| 52 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 53 TCN_ALLOC_CSTRING(filename); | |
| 54 | |
| 55 | |
| 56 UNREFERENCED(o); | |
| 57 rv = apr_shm_remove(J2S(filename), p); | |
| 58 TCN_FREE_CSTRING(filename); | |
| 59 | |
| 60 return (jint)rv; | |
| 61 } | |
| 62 | |
| 63 TCN_IMPLEMENT_CALL(jint, Shm, destroy)(TCN_STDARGS, jlong shm) | |
| 64 { | |
| 65 apr_shm_t *s = J2P(shm, apr_shm_t *); | |
| 66 | |
| 67 UNREFERENCED_STDARGS; | |
| 68 return (jint)apr_shm_destroy(s); | |
| 69 } | |
| 70 | |
| 71 TCN_IMPLEMENT_CALL(jlong, Shm, attach)(TCN_STDARGS, | |
| 72 jstring filename, | |
| 73 jlong pool) | |
| 74 { | |
| 75 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 76 const char *fname = NULL; | |
| 77 apr_shm_t *shm; | |
| 78 | |
| 79 | |
| 80 UNREFERENCED(o); | |
| 81 if (filename) | |
| 82 fname = (const char *)((*e)->GetStringUTFChars(e, filename, 0)); | |
| 83 TCN_THROW_IF_ERR(apr_shm_attach(&shm, fname, p), shm); | |
| 84 | |
| 85 cleanup: | |
| 86 if (fname) | |
| 87 (*e)->ReleaseStringUTFChars(e, filename, fname); | |
| 88 return P2J(shm); | |
| 89 } | |
| 90 | |
| 91 TCN_IMPLEMENT_CALL(jint, Shm, detach)(TCN_STDARGS, jlong shm) | |
| 92 { | |
| 93 apr_shm_t *s = J2P(shm, apr_shm_t *); | |
| 94 | |
| 95 UNREFERENCED_STDARGS; | |
| 96 return (jint)apr_shm_detach(s); | |
| 97 } | |
| 98 | |
| 99 TCN_IMPLEMENT_CALL(jlong, Shm, baseaddr)(TCN_STDARGS, jlong shm) | |
| 100 { | |
| 101 apr_shm_t *s = J2P(shm, apr_shm_t *); | |
| 102 | |
| 103 UNREFERENCED_STDARGS; | |
| 104 return P2J(apr_shm_baseaddr_get(s)); | |
| 105 } | |
| 106 | |
| 107 TCN_IMPLEMENT_CALL(jlong, Shm, size)(TCN_STDARGS, jlong shm) | |
| 108 { | |
| 109 apr_shm_t *s = J2P(shm, apr_shm_t *); | |
| 110 | |
| 111 UNREFERENCED_STDARGS; | |
| 112 return (jlong)apr_shm_size_get(s); | |
| 113 } | |
| 114 | |
| 115 TCN_IMPLEMENT_CALL(jobject, Shm, buffer)(TCN_STDARGS, jlong shm) | |
| 116 { | |
| 117 apr_shm_t *s = J2P(shm, apr_shm_t *); | |
| 118 jlong sz = (jlong)apr_shm_size_get(s); | |
| 119 void *a; | |
| 120 | |
| 121 UNREFERENCED(o); | |
| 122 | |
| 123 if ((a = apr_shm_baseaddr_get(s)) != NULL) | |
| 124 return (*e)->NewDirectByteBuffer(e, a, sz); | |
| 125 else | |
| 126 return NULL; | |
| 127 } | |
| OLD | NEW |